June 3, 2024

What is Cargo-nextest?

Cargo-nextest is a test runner for Rust

Enabling XML Output

Rust has built in support for unit tests using cargo test. Unfortunately cargo test does not support customizing output formats (though there is experimental support for JSON output). Instead we suggest using cargo-nextest.

cargo-nextest is an alternative test runner for Rust which, among other cool features, supports XML and JSON output. Install cargo-nextest as either a pre-built binary like this:

1curl -LsSf | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin

or install and compile from source.

Next add a .config/nextest.toml config file to tell cargo-nextest what output format to use and where the output should be written too, among other settings. Something like this:

2dir = "target/nextest"
4# This section defines the default nextest profile. Custom profiles are layered
5# on top of the default profile.
7retries = 0
8test-threads = "num-cpus"
9threads-required = 1
10status-level = "pass"
11final-status-level = "flaky"
12failure-output = "immediate"
13success-output = "never"
14fail-fast = true
15slow-timeout = { period = "60s" }
18fail-fast = false
21path = "junit.xml"
23report-name = "nextest-run"
24store-success-output = false
25store-failure-output = true

The default profile will use standard text output. The ci profile will use JUnit XML output.

Now run the tests with:

1cargo nextest run --profile=ci

Test Suite naming

You can change the name of the report with the report-name option. Nextest will use the test binary names for the <testsuite> and the individual test names for the <testcase>. However, Nextest does not currently support adding the filepaths and names.

Other Configuration

See an example of cargo-nextest invoked form a GitHub action here.

Documentation for the cargo-nextest config file.

Try it yourself or
request a demo

Get started for free

Try it yourself or
Request a Demo

Free for first 5 users