dotTrace 2024.3 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:

    Profile tests in Visual Studio
  6. The Unit Test Sessions window opens.

  7. Specify profiling options.

  8. After test execution is completed, a snapshot will be opened in the dotTrace 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. Select Profile Unit Tests in the list on the toolbar.

    Profile Unit Tests 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:

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

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

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

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

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

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

    7. 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 the 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. Under Run profiling, select Collect profiling data from start.

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

  7. Collect a snapshot using the Get Snapshot button in the profiling controller window. Learn more about how to control the profiling session

  8. Detach the profiler using the Detach button in the controller window.

  9. Analyze the collected snapshots using the dotTrace Viewer.

Configuration examples

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:\Program Files (x86)\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 the test framework itself, making it a challenging 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 the lack of permissions. If this is the case, try running dotTrace as administrator.

Last modified: 26 May 2024