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.
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