dotTrace 2018.3 Help

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

  1. Open a solution in Visual Studio.

  2. Open a file with unit tests.

  3. Choose a test class or a test method.

  4. Click the corresponding side bar mark in the left gutter.

  5. In the context menu, choose Profile:

    Profiling Tests with Unit Test Runner

  6. The Unit Test Sessions window opens.

  7. Specify profiling options in the Profiler Configuration window.

  8. After test execution is completed, a snapshot will be opened in the corresponding viewer.

You can also launch unit test profiling from ReSharper. Choose ReSharper | Unit Tests | Profile Unit Tests or ReSharper | Unit Tests | Profile All Tests from Solution on the menu bar.

To profile unit tests from ReSharper's Unit Test Sessions window:

  1. Select a node in the tree view of the Unit Test Sessions window.

  2. Click Profile Unit Tests ThemedIcon UtrProfile Screen Gray in the toolbar.

  3. Specify profiling options in the Profiler Configuration window.

  4. After test execution is completed, a snapshot will be displayed.

To profile unit tests using standalone dotTrace

  1. Run dotTrace as a standalone application.

  2. Choose the New Session | Local tab.

  3. In the central panel in Profile Application, select Standalone.

  4. 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:
    • nunit.exe for NUnit.

    • nunit-console.exe for NUnit.

    • MSTest.exe for MSTest.

    • xUnit-console.exe for xUnit.

  5. Specify the path to the .dll file with your unit tests and add arguments (if necessary) in the Arguments field.

  6. Optionally, select 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:
    1. Select Advanced.

    2. Click Filter Processes.

    3. In the opened Filter Processes window, add the nunit-console* filter.

  7. Specify profiling options in the Profiler Configuration window.

  8. Click Run.

Test Runner

Application

Arguments

nunit.exe for nUnit

Path to test runner executable.
Example: "C:\Program Files (x86)\NUnit 2.5.3\bin\net-2.0\nunit.exe"

Path to the dll file with unit tests.
Example: "C:\Projects\ConsoleApplication1\ConsoleApplication1Test\bin\Debug\ConsoleApplication1Test.dll"

nunit-console.exe for nUnit

Path to the test runner executable.
Example: "C:\Program Files (x86)\NUnit 2.5.3\bin\net-2.0\nunit-console.exe"

Path to the dll file with unit tests and name of xml file where test results are stored.
Example: "C:\Test progs\ConsoleApplication1nUnit\ConsoleApplication1nUnitTest.dll" /xml:C:\Temp\1.xml

MSTest.exe for MSTest

Path to the test runner executable.
Example: "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe"

Arguments:
  • /noisolation - run tests within the MSTest.exe process.

  • /testcontainer - load a file that contains tests that you want to run.

Example: /noisolation /testcontainer:"C:\Projects\ConsoleApplication1\ConsoleApplication1Test\bin\Debug\ConsoleApplication1Test.dll"

xUnit-console.exe for xUnit

Path to the test runner executable.
Example: "C:\Prog\xunit-1.5\xunit.console.exe"

Path to the dll file with unit tests and name of xml file where test results are stored.
Example: "C:\Projects\ConsoleApplication1\ConsoleApplication1xUnit\bin\Debug\ConsoleApplication1xUnit.dll" /xml 1.xml

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: 15 March 2019

See Also

How tos: