ReSharper 2016.1 Help

Unit Testing Assistance in C++

ReSharper helps discover run, and debug unit tests of Google C++ Testing Framework and Boost.Test framework (v. 1.59 and 1.60) right in Visual Studio.

With ReSharper, you can execute a single unit test, all tests in a file, project or solution. You can also execute any number of tests combined in a test session.

In this topic:

Discovering tests in current document

ReSharper discovers unit tests right in the editor and adds the corresponding action indicators next to each item in the editor:

ReSharper shows different indicators for unit tests in the editor
  • ThemedIcon.UnitTestingOptionsPage.Screen.[Gray] - a unit test that you can run or debug
  • ThemedIcon.TestMethodSuccess.Screen.[Gray] - the unit test passed during the last execution.
  • ThemedIcon.TestMethodFail.Screen.[Gray] - the unit test failed during the last execution.

Executing tests in the current document

There are several ways to run or debug unit tests in the current document. You can use action indicators, main menu or shortcuts:

  • To run or debug a single test or all tests in a test class, click on the action indicator next to it or set the caret on the test and press Alt+Enter . In the action list , choose Run / Debug for a test .
  • Alternatively, you can use the Run Unit Tests / Debug Unit Tests commands, which are available in the main menu (ReSharper | Unit Tests), in the context menu or with Ctrl+T,R / Ctrl+T,D shortcuts correspondingly. These commands work differently depending on the caret position or selection in the editor:
    • To run or debug a single test , set the caret at the test name or anywhere inside it in the editor .
    • To run several tests, select the desired tests in the editor .

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 in this 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 choosing ReSharper | Unit Tests | Repeat Previous Run in the menu or pressing Ctrl+T,T.

Discovering unit tests in solution

ReSharper adds the Unit Test Explorer Window to Visual Studio. Using this window, you can explore and run or debug unit tests in the entire solution. The window displays all tests in the 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 these files appear in the Unit Test Explorer as soon as you create them.

To open Unit Test Explorer, choose ReSharper | Unit Tests | Unit Tests or ReSharper | Windows | Unit Tests in the main menu or press Ctrl+Alt+T.

Unit Test Explorer allows you to do the following:

  • Explore tests in the solution: browse all unit tests in a list or tree view, search tests and filter by a substring, regroup unit tests by project, namespace, etc.
  • Navigate to source code of any test by double-clicking it in the view.
  • run or debug selected tests.
  • Create unit tests sessions from selected tests and/or add selected items to the current test session.
  • Export all tests from solution to a text, XML, or HTML file.
Unit Test Explorer displays test from the entire solution

Executing 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 , 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 toolbar__run_selected_tests / Debug Unit Tests uts_toolbar_debug_selected_tests on the toolbar or use the corresponding shortcuts (Ctrl+T,R / Ctrl+T,D ).
  • To run or debug tests from Solution Explorer or Class View, select one or more items ( files, folders, projects) that contain tests, and use the Run Unit Tests / Debug Unit Tests commands, which are available in the main menu (ReSharper | Unit Tests), in the context menu or with Ctrl+T,R / Ctrl+T,D shortcuts correspondingly.
  • To run or debug all tests in solution, choose ReSharper | Unit Tests | Run All Tests from Solution in the main menu or press Ctrl+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 in this 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 choosing ReSharper | Unit Tests | Repeat Previous Run in the menu or pressing Ctrl+T,T.

Using Unit Test Sessions

ReSharper allows you to group unit tests that target specific part of your application into unit test sessions. A unit test session can contain tests from different projects. You can have multiple test sessions and run them separately as needed. A single test can be included into several different test sessions.

For detailed instructions related to unit test sessions, see Using Unit Test Sessions.

Execution process

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.

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 uts_toolbar_stop_execution 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 uts_toolbar_track_running_test 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 ThemedIcon.ScrollToBottom.Screen.[Gray] option to follow output of tests as they are running.

When you debug unit tests, ReSharper uses the following configuration parameters specified in the project properties: Command, Command Arguments, Working Directory. To access these properties, right-click on the project and choose Project Properties | Configuration Properties | Debugging.

cpp_unit_test_sessions

Analysing execution results and output

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

The output pane (which you can place on the right or on the bottom using the Show Output toolbar_show_preview button on the toolbar) displays output of the selected test.

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 Tools | Unit Testing options page.

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

  • ThemedIcon.RunningTest.Screen.[Gray] - the unit test is currently executing.
  • ThemedIcon.TestPending.Screen.[Gray] - the unit test is scheduled for execution in the current run.
  • ThemedIcon.StatusUnknown.Screen.[Gray] - the unit test was not executed.
  • ThemedIcon.Success.Screen.[Gray] - the unit test passed in the lats test run.
  • ThemedIcon.Error.Screen.[Gray] - the unit test failed in the lats test run.
  • ThemedIcon.Ignore.Screen.[Gray] - the unit test was ignored in the last test run.
  • ThemedIcon.StatusAborted.Screen.[Gray] - the unit test was aborted in the last test run.

The same icons are used to display status of grouping items

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 ThemedIcon.UnitSession.Screen.[Gray] icon shows the total number of tests in the session.

Last modified: 19 August 2016