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[profile.ci]2fail-fast = false34[profile.ci.junit]5path = "junit.xml"
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.