![](https://www.datocms-assets.com/98527/1717435899-cnlogo.png)
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 https://get.nexte.st/latest/linux | 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:
1[store]2dir = "target/nextest"34# This section defines the default nextest profile. Custom profiles are layered5# on top of the default profile.6[profile.default]7retries = 08test-threads = "num-cpus"9threads-required = 110status-level = "pass"11final-status-level = "flaky"12failure-output = "immediate"13success-output = "never"14fail-fast = true15slow-timeout = { period = "60s" }1617[profile.ci]18fail-fast = false1920[profile.ci.junit]21path = "junit.xml"2223report-name = "nextest-run"24store-success-output = false25store-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.