3

How can we generate an HTML report of unit test or integration test after running cargo test in the Rust programming language?

As an Automation Tester, I've been working on an existing Rust Automation Testing Project which is running as Integration Test. Like Java and Maven, I also want to generate HTML reports for the results of automation test cases.

E_net4
  • 27,810
  • 13
  • 101
  • 139
The Sun
  • 503
  • 1
  • 3
  • 13
  • I'm not aware of any better solution than parsing the `cargo test` and `cargo test -- --list` output. That appears to be what the [VS Code Rust Test Explorer extension](https://github.com/swellaby/vscode-rust-test-adapter) is doing as well. – Sven Marnach Sep 09 '22 at 10:05

1 Answers1

5

While reporting the outcome as an HTML document is not yet available in the Rust compiler, there are some crates out there which take the test runner's output in some form and convert it into structured test reports. They often depend on JSON output, which is an unstable feature at the time of writing, thus requiring a nightly toolchain. A few of these crates follow, intentionally a non-exhaustive list (do look up crates.io for more).

markdown-test-report converts the test results into markdown, which can be easily rendered into HTML.

cargo +nightly test -- --format=json -Z unstable-options --report-time > test-report.json
markdown-test-report test-report.json test-report.md
# using pandoc for example
pandoc test-report.md -o test-report.html

junitify turns JSON output into multiple JUnit XML reports. These too can be converted into HTML documents.

cargo +nightly test -- --format=json -Z unstable-options --report-time | junitify -o test-results/
# using xunit-viewer for example
xunit-viewer -r test-results -o test-report.html
E_net4
  • 27,810
  • 13
  • 101
  • 139