Uploading JUnit test report files to Datadog

Uploading JUnit test report files to Datadog

JUnit test report files are XML files that contain test execution information, such as test and suite names, pass/fail status, duration, and sometimes error logs. Although it was introduced by the JUnit testing framework, many other popular frameworks are able to output results using this format.

As an alternative to instrumenting your tests natively using Datadog tracers, which is the recommended option as it provides the most comprehensive test results, you can also upload JUnit XML test reports.

Test results imported from JUnit XML reports appear alongside test data reported by tracers. However, there are some limitations when using this method, such as the lack of distributed traces on integration tests or structured stack traces. For this reason, only use this method if there is no native support for the language or testing framework being used.

Installing the Datadog CI CLI

Install the datadog-ci CLI globally using npm:

npm install -g @datadog/datadog-ci

Uploading test reports

To upload your JUnit XML test reports to Datadog, run the following command, specifying the name of the service or library that was tested using the --service parameter, and one or more file paths to either the XML report files directly or directories containing them:

datadog-ci junit upload --service <service_name> <path> [<path> ...]

Specify a valid Datadog API key in the DATADOG_API_KEY environment variable, and the environment where tests were run (for example, local when uploading results from a developer workstation, or ci when uploading them from a CI provider) in the DD_ENV environment variable. For example:

DD_ENV=ci DATADOG_API_KEY=<api_key> datadog-ci junit upload \
  --service my-api-service \
  unit-tests/junit-reports e2e-tests/single-report.xml

DD_ENV=ci DATADOG_API_KEY=<api_key> DATADOG_SITE=datadoghq.eu datadog-ci junit upload \
  --service my-api-service \
  unit-tests/junit-reports e2e-tests/single-report.xml

Configuration settings

This is the full list of options available when using the datadog-ci junit upload command:

--service (Required)
Name of the service or library under test.
Environment variable: DD_SERVICE
Example: my-api-service
Environment where tests were run.
Environment variable: DD_ENV
Example: ci
Key-value pairs in the form key:value to be attached to all tests (the --tags parameter can be specified multiple times). When specifying tags using DD_TAGS, separate them using commas (for example, team:backend,priority:high).
Environment variable: DD_TAGS
Default: (none)
Example: team:backend
Note: Tags specified using --tags and with the DD_TAGS environment variable are merged. If the same key appears in both --tags and DD_TAGS, the value in the environment variable DD_TAGS takes precedence.
The number of concurrent uploads to the API.
Default: 20
Runs the command without actually uploading the file to Datadog. All other checks are performed.
Default: false
Positional arguments
The file paths or directories in which the JUnit XML reports are located. If you pass a directory, the CLI looks for all .xml files in it.

The following environment variables are supported:

Datadog API key used to authenticate the requests.
Default: (none)

Additionally, configure the Datadog site to use the selected one ():

The Datadog site to upload results to.
Default: datadoghq.com
Selected site:

Collecting repository and commit metadata

The Datadog CI CLI tries to extract git repository and commit metadata from CI provider environment variables and from the local .git directory and attach it to test executions. In order to read this directory, the git binary is required.

Further reading

The selected Datadog site () is not supported at this time.