dotTrace 2021.1 Help

Profile Unit Tests

There are three ways of profiling unit tests:

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 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.

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

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 Themed icon utr profile screen gray in the toolbar.

  3. Specify profiling options.

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

To profile unit tests using the standalone dotTrace

  1. Run dotTrace as a standalone application. The dotTrace Home window will open.

  2. Add a run configuration - the configuration that tells dotTrace how to run the profiled application:

    • Under Choose what you want to profile, New Process Run, click Add run configuration Add run configuration.

    • In the New Run Configuration wizard, choose .NET Core Application and click Next.

    • Depending on which unit testing framework you use, specify the path to its executable file in the Path 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.

      See more configuration examples.

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

    • If required, specify a full path to the application Working directory (by default, it's the same directory where the executable is located).

    • If required, use Set environment variables to specify environment variables. Each variable must be specified on a new line.

    • Click Save.

  3. Make sure the created run configuration is selected in the New Process Run list.

  4. Under Choose how you want to profile it, specify profiling options:

    • Profiling Type: typically, you should choose between Sampling (evaluate performance and determine slowest methods in your app) and Timeline (same as Sampling but with additional timeline data). Learn more about profiling types

    • Optionally, if your application creates a number of processes and you want to profile only specific ones, create process filters.

      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, add the nunit-console* filter.

    • If required, specify other profiling options.

  5. If you want dotTrace to start collecting profiling data right after you start the session, under Run profiling, select Collect profiling data from start.

  6. Click Start. This will start the profiling session.

  7. Go through a particular workflow in your application (if you want to evaluate its performance) or reproduce a particular performance issue. Collect snapshots using the Get Snapshot button in the profiling controller window. Learn more about how to control the profiling session

  8. After you collect the data, either close the profiled application or detach the profiler using the Detach button in the controller window.

  9. Analyze the collected snapshots either in the Performance Viewer or Timeline Viewer (depends on the profiling type you select).

Configuration examples

Test RunnerApplicationArguments
nunit.exe for nUnitPath 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 nUnitPath 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 MSTestPath 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 xUnitPath 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: 08 March 2021