ReSharper 2016.3 Help

Executing Tests and Analyzing Results

ReSharper provides several ways to execute unit tests. Whichever way you choose, execution progress, results, and output are displayed in the Unit Test Sessions window.

In this topic:

Different ways of running and debugging unit tests

There are following ways to run or debug unit tests:

  • Use one of the ways to execute tests in the current document.
  • Use one of the ways to execute tests in the project/solution,
  • If there is an existing unit test session, you can run or debug some or all tests in the session:
    • Select tests that you want to execute in the Unit Test Sessions window and click Run Unit Tests /help/img/dotnet/2016.3/ThemedIcon.RunTest.Screen.[Gray].png / Debug Unit Tests /help/img/dotnet/2016.3/ThemedIcon.Debug.Screen.[Gray].png on the toolbar or press Ctrl+T,R / Ctrl+T,D .
    • To run all tests in the session, click Run All Tests /help/img/dotnet/2016.3/ThemedIcon.RunAll.Screen.[Gray].png on the toolbar or alternatively, choose ReSharper | Unit Tests | Run Current Session in the main menu or press Ctrl+T,Y .

As the tests are running in a unit test session, the execution progress is shown in the status bar under the toolbar of the Unit Test Sessions window and the Stop Execution /help/img/dotnet/2016.3/ThemedIcon.StopTest.Screen.[Gray].png button becomes active. You can click this button to abort execution of the tests. You can run multiple unit test sessions simultaneously. However, when you debug tests, only one test session can be executed at a time.

If necessary, you can enable the Track Running Test /help/img/dotnet/2016.3/ThemedIcon.TrackRun.Screen.[Gray].png option on the toolbar. If it is on, the selection in the test tree switches automatically to the test that is currently running and the output panel always shows output of the current test during the execution.

You can also enable the Auto Scroll Output When Running Test /help/img/dotnet/2016.3/ThemedIcon.ScrollToBottom.Screen.[Gray].png option to follow output of tests as they are running.

If necessary, you can always re-run the tests that you executed last by clicking Repeat Previous Run /help/img/dotnet/2016.3/ThemedIcon.Rerun.Screen.[Gray].png on the toolbar, choosing ReSharper | Unit Tests | Repeat Previous Run in the menu or pressing Ctrl+T,T.

Analysing execution results and output

When the execution is over, the results are visualized in the Unit Test Sessions window.

/help/img/dotnet/2016.3/unit_test_sessions.png

The output pane (which you can place on the right or on the bottom using the Show Output /help/img/dotnet/2016.3/ThemedIcon.PreviewToggle.Screen.[Gray].png button on the toolbar) displays output of the selected test. If the test is failed, ReSharper also adds short information on the failure and/or displays the stack trace of an exception. You can use clickable links in the output pane to navigate directly to types and methods involved with the failure. If the output displays a link to a file that does not belong to the solution, you can click this link to open the file in an external application associated with the corresponding file type or Ctrl - click to open it in Visual Studio.

If you want to inspect specific stack trace later, press Ctrl+Shift+Alt+E or click Show Stack Trace in a new window /help/img/dotnet/2016.3/ThemedIcon.StackTraceExplorerToolWindow.Screen.[Gray].png on the toolbar to open the stack trace in a new tab of the Stack Trace Explorer window.

By default, ReSharper wraps long lines in the output according to the current width of the output area. If necessary, you choose not to wrap long lines by clearing the Wrap long lines in Unit Test Session output check-box on the ReSharper | Options | Tools | Unit Testing page of ReSharper options.

Status of each test in the Unit Test Sessions window is displayed with one of the following icons:

  • /help/img/dotnet/2016.3/ThemedIcon.RunningTest.Screen.[Gray].png - the unit test is currently executing.
  • /help/img/dotnet/2016.3/ThemedIcon.TestPending.Screen.[Gray].png - the unit test is scheduled for execution in the current run.
  • /help/img/dotnet/2016.3/ThemedIcon.StatusUnknown.Screen.[Gray].png - the unit test was not executed.
  • /help/img/dotnet/2016.3/ThemedIcon.Success.Screen.[Gray].png - the unit test passed in the lats test run.
  • /help/img/dotnet/2016.3/ThemedIcon.Error.Screen.[Gray].png - the unit test failed in the lats test run.
  • /help/img/dotnet/2016.3/ThemedIcon.Ignore.Screen.[Gray].png - the unit test was ignored in the last test run. Either it has the corresponding attribute (e.g. Ignore for NUnit tests) or it is included in a category that is ignored in ReSharper settings.
  • /help/img/dotnet/2016.3/ThemedIcon.StatusAborted.Screen.[Gray].png - the unit test was aborted in the last test run.

The same icons are used to display status of grouping items (classs, projects, etc.)

The icons are also used on each session's tab to display the overall execution result of the sessions.

The corresponding icons on the status bar show how many tests are in each of the status. The /help/img/dotnet/2016.3/ThemedIcon.UnitSession.Screen.[Gray].png icon shows the total number of tests in the session.

Customizing execution process

By default, ReSharper uses unit test project settings to define which .NET Framework version and processor architecture should be used when executing tests.

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 execution. You can avoid such situation, by specifying explicitly what CLR (.NET Framework) should be used. To do so, use the Default .NET Framework version selector on the ReSharper | Options | Tools | Unit Testing page of ReSharper options. This preference affects tests running under NUnit, XUnit and MSpec test frameworks. It has no effect on tests running under MsTest yet.

You can also change the platform architecture (32-bit or 64-bit) using the Default platform architecture selector on that options page.

If necessary, you can override these settings for specific unit test session using the Options selector on the toolbar.

Studying execution log

Unit Test Sessions window includes test execution log that lets you separate problems related to test execution process from unit tests code.
You will normally need to check execution log if some of your tests have the 'Inconclusive' state after execution, which could be a sign of an error occurring in the test runner.

If you have errors reported either by the test runner or ReSharper, the number of errors is displayed on the right side of the window's status bar, else OK is shown.
To display or hide the execution log, click the Log /help/img/dotnet/2016.3/ThemedIcon.SessionLog.Screen.[Gray].png button.

By default, only events with the 'Error' severity level are logged. If necessary, you can change the minimum severity level. To do so, either right-click the log area and choose the desired severity level or use the Show log entries... selector on the Tools | Unit Testing page of ReSharper options.

You can also copy the whole log to the clipboard by choosing the corresponding command in the context menu.

Last modified: 3 April 2017