JUnit support

cargo-nextest can produce output in the JUnit/XUnit XML format. This format is widely understood by test analysis tools and libraries.

To enable JUnit support, add this to your configuration:

[profile.ci.junit]  # this can be some other profile, too
path = "junit.xml"

If --profile ci is selected on the command line, a JUnit report will be written out to target/nextest/ci/junit.xml within the workspace root.

Some notes about the JUnit support:

  • There are several slightly different formats all called "JUnit" or "XUnit". cargo-nextest adheres to the Jenkins XML format.
  • Every test binary forms a single <testsuite>. Every test forms a single <testcase>.
  • Standard output and standard error are included for failed and retried tests. (However, invalid XML characters are stripped out.)

Post-processing

Some tools that read JUnit files don't follow the Jenkins standard. You can post-process the JUnit file in such cases. Here's some recommendations for post-processing tools written by community members:

Example

Here's an example JUnit file generated by cargo-nextest.

<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="nextest-run" tests="3" failures="1" errors="0" uuid="9ea8d2ee-e485-4e5b-8dba-4985c12081f7" timestamp="2022-07-28T01:09:27.584+00:00" time="0.007">
    <testsuite name="nextest-tests::basic" tests="3" disabled="0" errors="0" failures="1">
        <testcase name="test_cwd" classname="nextest-tests::basic" timestamp="2022-07-28T01:09:27.584+00:00" time="0.002">
        </testcase>
        <testcase name="test_failure_assert" classname="nextest-tests::basic" timestamp="2022-07-28T01:09:27.585+00:00" time="0.002">
            <failure type="test failure">thread &apos;test_failure_assert&apos; panicked at &apos;assertion failed: `(left == right)`
  left: `4`,
 right: `5`: this is an assertion&apos;, tests/basic.rs:9:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace</failure>
            <rerunFailure timestamp="2022-07-28T01:09:27.586+00:00" time="0.002" type="test failure">thread &apos;test_failure_assert&apos; panicked at &apos;assertion failed: `(left == right)`
  left: `4`,
 right: `5`: this is an assertion&apos;, tests/basic.rs:9:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
                <system-out>
running 1 test
test test_failure_assert ... FAILED

failures:

failures:
    test_failure_assert

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 17 filtered out; finished in 0.00s

</system-out>
                <system-err>thread &apos;test_failure_assert&apos; panicked at &apos;assertion failed: `(left == right)`
  left: `4`,
 right: `5`: this is an assertion&apos;, tests/basic.rs:9:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
</system-err>
            </rerunFailure>
            <rerunFailure timestamp="2022-07-28T01:09:27.588+00:00" time="0.002" type="test failure">thread &apos;test_failure_assert&apos; panicked at &apos;assertion failed: `(left == right)`
  left: `4`,
 right: `5`: this is an assertion&apos;, tests/basic.rs:9:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
                <system-out>
running 1 test
test test_failure_assert ... FAILED

failures:

failures:
    test_failure_assert

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 17 filtered out; finished in 0.00s

</system-out>
                <system-err>thread &apos;test_failure_assert&apos; panicked at &apos;assertion failed: `(left == right)`
  left: `4`,
 right: `5`: this is an assertion&apos;, tests/basic.rs:9:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
</system-err>
            </rerunFailure>
            <system-out>
running 1 test
test test_failure_assert ... FAILED

failures:

failures:
    test_failure_assert

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 17 filtered out; finished in 0.00s

</system-out>
            <system-err>thread &apos;test_failure_assert&apos; panicked at &apos;assertion failed: `(left == right)`
  left: `4`,
 right: `5`: this is an assertion&apos;, tests/basic.rs:9:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
</system-err>
        </testcase>
        <testcase name="test_flaky_mod_4" classname="nextest-tests::basic" timestamp="2022-07-28T01:09:27.589+00:00" time="0.001">
            <flakyFailure timestamp="2022-07-28T01:09:27.586+00:00" time="0.002" type="test failure">thread &apos;test_flaky_mod_4&apos; panicked at &apos;Failed because attempt 1 % 4 != 0&apos;, tests/basic.rs:33:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
                <system-out>
running 1 test
test test_flaky_mod_4 ... FAILED

failures:

failures:
    test_flaky_mod_4

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 17 filtered out; finished in 0.00s

</system-out>
                <system-err>thread &apos;test_flaky_mod_4&apos; panicked at &apos;Failed because attempt 1 % 4 != 0&apos;, tests/basic.rs:33:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
</system-err>
            </flakyFailure>
            <flakyFailure timestamp="2022-07-28T01:09:27.587+00:00" time="0.002" type="test failure">thread &apos;test_flaky_mod_4&apos; panicked at &apos;Failed because attempt 2 % 4 != 0&apos;, tests/basic.rs:33:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
                <system-out>
running 1 test
test test_flaky_mod_4 ... FAILED

failures:

failures:
    test_flaky_mod_4

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 17 filtered out; finished in 0.00s

</system-out>
                <system-err>thread &apos;test_flaky_mod_4&apos; panicked at &apos;Failed because attempt 2 % 4 != 0&apos;, tests/basic.rs:33:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
</system-err>
            </flakyFailure>
        </testcase>
    </testsuite>
</testsuites>