ReSharper Web Help

ReSharper provides Unit Test Explorer for viewing tests and arranging test sessions, and the Unit Test Sessions window for running test sessions and viewing test results. So, with ReSharper you can:

Run and debug tests

To run tests from Unit Test Explorer
  1. Make sure that your project has been built. Otherwise, ReSharper will not be able to populate Unit Test Explorer with the list of test fixtures that it contains.
  2. Open the Unit Test Explorer window. To do that, do one of the following:
    • On the main menu, choose ReSharper | Unit Tests | Unit Tests.
    • On the main menu, choose ReSharper | Windows | Unit Tests.
    • Press Ctrl+Alt+TCtrl+Alt+U.
  3. Select test(s) that you want to run:

    Unit_Testing__Running_and_Debugging_Unit_Tests_01

  4. Click one of the following buttons in the Unit Test Explorer toolbar:
    • Run Selected Tests toolbar__run_selected_tests to run selected tests in the currently active session of the Unit Test Sessions window.
    • Append Selected Tests to Session toolbar__append_selected_tests_to_session to include selected tests into the session tab that is currently active in the Unit Test Sessions window, without running them right away.
    • New Session with Selected Tests toolbar__new_session_with_selected_tests to create a new session in the Unit Test Sessions window containing the selected tests, without running them right away.
  5. Depending on which command you have chosen in the previous step, selected tests display or run in the Unit Test Sessions window:

    Unit_Testing__Running_and_Debugging_Unit_Tests_02

To run tests from the text editor, File Structure or Solution Explorer
  1. Open a class in the editor or select a test in File Structure, or select a node (project or solution node) in the Solution Explorer.
  2. Do one of the following:
    • On the main menu, choose ReSharper | Unit Tests | Run Unit Tests.
    • Right-click, then click Run Unit Tests on the context menu.
    • Press Ctrl+T,RCtrl+U,R.
    The Unit Test Sessions window opens when you start running tests.

In the Unit Test Sessions window, next to your tests you can see one of the following messages that reflect the status of each test:

  • Success - test successfully passed
  • Failed - test failed
  • Ignored - test was not run, test or class where it is declared is marked as ignored
  • Aborted - during test run you explicitly stopped execution
  • Inconclusive - test failed with inconclusive result, it means that this test wasn't verified or some logic hasn't been implemented yet
The way to ignore a test or mark a test as inconclusive depends on the test framework you use.
Unit_Testing__Running_and_Debugging_Unit_Tests_04

ReSharper keeps the results of each session. If you close your solution and open it again, you still have the last run results. They are marked with question marks. These marks inform that results may be outdated because the code might have changed since the last run.
Unit_Testing__Running_and_Debugging_Unit_Tests_05

To debug tests from the text editor, File Structure or Solution Explorer
  1. Open a class in the editor or select a test in File Structure, or select a node (project or solution node) in Solution Explorer.
  2. Do one of the following:
    • On the main menu, choose ReSharper | Unit Tests | Debug Unit Tests.
    • Right-click, then click Debug Unit Tests on the context menu.
    • Press Ctrl+T,DCtrl+U,D.
    The Unit Test Sessions window opens when you start debugging tests.

Note

When tests are run or debugged from the editor, the caret position defines which test or tests will be involved. If the caret is inside a test method, that single test is run or debugged. If it is outside any test method, the entire test class contained in the current file is run or debugged.

To run or debug an individual test using side bar marks
  1. In the editor, open a class that contains unit tests.
  2. Click a side bar mark in the gutter.
  3. On the context menu, click Run or Debug to run or debug tests that the test class contains, or click Append to Session to include the tests into the specified (or a new) session in the Unit Test Sessions window (note that you can't add tests to a locked unit test session).

    Unit_Testing__Recognizing_Unit_Tests__test_fixture

    Individual test marks let you run and debug a single test independently of other tests in the same class:

    Unit_Testing__Recognizing_Unit_Tests__test

  4. A selected test or all tests in a class are run as a single session in the Unit Test Sessions window where you're able to review the test results.

When tests in your project use, sometimes indirectly or implicitly, an assembly based on CLR2 and your project already targets CLR4, errors may occur during test run. To avoid such situation, specify explicitly what CLR should be used.

To specify default CLR version
  1. On the main menu, choose ReSharper | Options. The Options dialog box opens.
  2. On the left pane of the dialog box, click Tools, then click Unit Testing.
  3. Specify a version using the Default .NET Framework version drop-down list. Click one of the following:
    • Automatic based on test project's target framework
    • Force tests to use CLR 2.0
    • Force tests to use CLR 4.0
  4. Click Save or Save To to save and apply changes.

    Note

    ReSharper maintains several settings layers, so pay attention what layer you modify. For more information, see Managing and Sharing Options.

This setting affects tests running under NUnit, XUnit and MSpec test frameworks. It has no effect on tests running under MsTest yet.

Sometimes it's also necessary to run tests using different architecture. You can specify once what platform to use and run all tests on it.

To set default platform architecture
  1. On the main menu, choose ReSharper | Options. The Options dialog box opens.
  2. On the left pane of the dialog box, click Tools, then Unit Testing.
  3. Specify platform architecture using the Default platform architecture drop-down list. Click one of the following:
    • Automatic based on test project's target platform
    • Use platform-independent (AnyCPU) runner
    • Force tests to run 32-bit process
    • Force tests to run 64-bit process
  4. Click Save or Save To to save and apply changes.

    Note

    ReSharper maintains several settings layers, so pay attention what layer you modify. For more information, see Managing and Sharing Options.

Add tests to a session

To add tests to a new session
  • In the editor, click a side bar mark. On the context menu, click Append to Session, depending on your goal click Create New Session or click [session name].

    Unit_Testing__Recognizing_Unit_Tests__append_01

  • In the Unit Test Explorer window, right-click a test to run, then click Create New Session or click [session name] on the context menu.

Quick unit test search

Starting with ReSharper 7.1 you can quickly filter unit tests in the Unit Test Session window. To do that, start typing text to be matched when the the Unit Test Session window is focused.

Unit_Testing__Running_and_Debugging_Unit_Tests_03

Lock a session

You can easily lock the active session, so all new tests will be run in a new session and can't be included in the locked one. To do that, click Lock Session uts_toolbar_lock_session on the toolbar of the Unit Test Sessions window.

Work with a group of tests

If you create automated tests, you probably use categories to simplify test management. You add test categories as attributes to your test methods or test classes.
Unit_Testing__Recognizing_Unit_Tests__category_02
The AspBlockCommentTest class has the Category attribute, and all test methods within the class belong to this category. So you can work with a particular test or a group of tests from the same category.

Unit_Testing__Recognizing_Unit_Tests__category_01

To run or debug a specific group of tests using side bar marks
  1. In the editor, open a class that contains unit tests.
  2. Click a side bar mark in the gutter.
  3. On the context menu, click Category "[category name]", then click Run or Debug depending on the goal.

Ignore a group of tests

To ignore a specific group of tests
  1. On the main menu, choose ReSharper | Options. The Options dialog box opens.
  2. Click the Unit Testing node in the left tab.
  3. In the Unit Testing tab, type names of categories that should be ignored in the Don't run tests from categories box.
  4. Click Save or Save To to apply changes.

ReSharper supports TestCase, TestCaseSource, Values and other attributes.