ReSharper 2021.2 Help

Working with unit tests in project or solution

Discover unit tests in solution

ReSharper adds the Unit Test Explorer window to Visual Studio (ReSharper | Unit Tests | Unit Tests or ReSharper | Windows | Unit Tests, or Control+Alt+T). Using this window, you can explore and run or debug unit tests of all supported frameworks in the entire solution. Note that unit tests from a project only appear in the window after the project is built. Tests from currently opened files are updated automatically, new tests from the opened files appear in the unit test explorer as soon as you create them.

For each test framework, you can prefer either speed or accuracy for discovering unit tests after the build by choosing one of the following options on the Tools | Unit Testing | Test Frameworks | <Framework> page of ReSharper options (Alt+R, O):

  • Metadata (default)

    In this mode, ReSharper analyzes the build artifact without launching the test runner.

    As tests are defined using attributes, ReSharper can quickly scan the metadata of managed artifacts to find most tests in the project. However, it may fail to find tests that require running some special hooks of the framework to define their parameters.

    This is the fastest way of discovering tests.

  • Test runner

    In this mode, ReSharper launches the framework runner in the discovery mode on the build artifact, and then uses the results from the runner.

    Using the framework runner can take considerably longer to analyze the project, but the list of discovered tests will be complete in most cases.

Unit Test Explorer displays tests from the entire solution

In the unit test explorer, you can:

  • Explore tests in the solution: browse all unit tests in a tree view, search tests and filter by a substring, regroup unit tests by project, namespace, category, and so on.

  • Navigate to source code of any test or test class by double-clicking it in the view.

  • run or debug selected tests.

  • Create unit tests sessions from selected tests and test classes and/or add selected items to the current test session.

run or debug unit tests in project or solution

You can run or debug tests from the Unit Test Explorer, Solution Explorer, or Class View. Unit Test Explorer gives you the advantage to see only tests and test classes, while using other windows you need to know, which projects, files, and classes contain tests.

  • To execute tests from Unit Test Explorer, select the desired tests and click Run Unit Tests Run Unit Tests Control+T R/ Debug Unit Tests Debug Unit Tests Control+T D on the toolbar.

  • To run or debug tests from Solution Explorer or Class View, select one or more items ( classes, files, folders, projects) that contain tests, and use the Run Unit Tests Run Unit Tests Control+T R/ Debug Unit Tests Debug Unit Tests Control+T D commands, which are also available in the main menu (ReSharper | Unit Tests) and in the context menu.

  • To run or debug all tests in solution, choose ReSharper | Unit Tests | Run All Tests from Solution in the main menu or press Control+T L.

Whatever way you choose to run or debug tests, you will see the execution progress, results, and output in the Unit Test Sessions window. If there is an open unit test session, the executed tests are added to that session. If there are no test sessions or the existing ones are locked, then a new tests session is created.

If necessary, you can always re-run the tests that you executed last by pressing Control+T T or choosing ReSharper | Unit Tests | Repeat Previous Run in the menu.

Last modified: 19 August 2021