5

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.

1
  • 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 is doing as well. Commented Sep 9, 2022 at 10:05

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.