Profile Unit Test
There are three ways of profiling unit tests:
- Using dotTrace integrated in Visual Studio.
This is the most convenient way. - Using dotTrace and ReSharper (only if you have ReSharper or ReSharper Ultimate installed on your machine).
- Using standalone dotTrace. *
To profile unit tests using dotTrace integrated in Visual Studio:
- Open a solution in Visual Studio.
- Open a file with unit tests.
- Choose a test class or a test method.
- Click the corresponding side bar mark in the left gutter.
- In the context menu, choose Profile:
- The Unit Test Sessions window opens.
- Specify profiling options in the Profiler Configuration window.
- After test execution is completed, a snapshot will be opened in the corresponding viewer.
You can also launch unit test profiling from ReSharper. Choose or on the menu bar.
To profile unit tests from ReSharper's Unit Test Sessions window:
- Select a node in the tree view of the Unit Test Sessions window.
- Click Profile Unit Tests in the toolbar.
- Specify profiling options in the Profiler Configuration window.
- After test execution is completed, a snapshot will be displayed.
To profile unit tests using standalone dotTrace:
- Run dotTrace as a standalone application.
- Choose the New Session | Local tab.
- In the central panel in Profile Application, select Standalone.
- Depending on which unit testing framework you use, specify the path to its executable file in the Application field. Your can work with the following frameworks/executables:
- Specify the path to the
.dll
file with your unit tests and add arguments (if necessary) in the Arguments field. - Optionally, turn on the Advanced option to configure additional options, such as Working Directory and Profile child processes.
For example, if you need to profile NUnit tests running under nunit-console.exe, note that NUnit test runner creates a separate process to run tests. Therefore you need to exclude the nunit-console.exe process from profiling. To do this: - Specify profiling options in the Profiler Configuration window.
- Click Run.
The resulting snapshot contains lots of information that pertains not only to the unit tests you're profiling but to test framework itself, making it a difficult task to extract information about unit tests. If you don't find unit test code in the snapshot at all, make sure the tests are actually running. In some cases MSTest stops before running tests due to inadequate permissions. If this is the case, try running dotTrace as administrator.
Last modified: 24 August 2017