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.
datadog-ci CLI globally using
npm install -g @datadog/datadog-ci
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
This is the full list of options available when using the
datadog-ci junit upload command:
key:valueto be attached to all tests (the
--tagsparameter can be specified multiple times). When specifying tags using
DD_TAGS, separate them using commas (for example,
--tagsand with the
DD_TAGSenvironment variable are merged. If the same key appears in both
DD_TAGS, the value in the environment variable
.xmlfiles in it.
The following environment variables are supported:
Additionally, configure the Datadog site to use the selected one ():
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.
The selected Datadog site () is not supported at this time.