.NET Tests

.NET Tests

CI Visibility is not available in the selected site () at this time.


Supported .NET versions:

  • .NET Core >= 2.1 and >= 3.0
  • .NET >= 5.0

Supported test frameworks:

  • xUnit >= 2.2
  • NUnit >= 3.0
  • MsTest V2 >= 14


Install the Datadog Agent to collect tests data.

Installing the .NET tracer

To install or update the dd-trace command globally on the machine, run:

dotnet tool update -g dd-trace

Instrumenting tests

To instrument your test suite, prefix your test command with dd-trace, providing the name of the service or library under test as the --dd-service parameter, and the environment where tests are being run (for example, local when running tests on a developer workstation, or ci when running them on a CI provider) as the --dd-env parameter. For example:

dd-trace --dd-service=my-dotnet-app --dd-env=ci -- dotnet test

All tests are automatically instrumented.

Configuration settings

You can change the default configuration of the CLI by using command line arguments or environment variables. For a full list of configuration settings, run:

dd-trace --help

The following list shows the default values for key configuration settings:

Name of the service or library under test.
Environment variable: DD_SERVICE
Default: The repository name
Example: my-dotnet-app
Name of the environment where tests are being run.
Environment variable: DD_ENV
Default: none
Examples: local, ci
Datadog Agent URL for trace collection in the form http://hostname:port.
Environment variable: DD_TRACE_AGENT_URL
Default: http://localhost:8126

All other Datadog Tracer configuration options can also be used.

Collecting Git metadata

Datadog uses Git information for visualizing your test results and grouping them by repository, branch, and commit. Git metadata is automatically collected by the test instrumentation from CI provider environment variables and the local .git folder in the project path, if available.

If you are running tests in non-supported CI providers or with no .git folder, you can set the Git information manually using environment variables. These environment variables take precedence over any auto-detected information. Set the following environment variables to provide Git information:

URL of the repository where the code is stored. Both HTTP and SSH URLs are supported.
Example: git@github.com:MyCompany/MyApp.git, https://github.com/MyCompany/MyApp.git
Git branch being tested. Leave empty if providing tag information instead.
Example: develop
Git tag being tested (if applicable). Leave empty if providing branch information instead.
Example: 1.0.1
Full commit hash.
Example: a18ebf361cc831f5535e58ec4fae04ffd98d8152
Commit message.
Example: Set release number
Commit author name.
Example: John Smith
Commit author email.
Example: john@example.com
Commit author date in ISO 8601 format.
Example: 2021-03-12T16:00:28Z
Commit committer name.
Example: Jane Smith
Commit committer email.
Example: jane@example.com
Commit committer date in ISO 8601 format.
Example: 2021-03-12T16:00:28Z

Further reading