How can we generate HTML reports of unit test or integration test runs in Rust?
Asked Answered
A

1

6

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.

Altagraciaaltaic answered 9/9, 2022 at 9:30 Comment(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.Enhanced
G
6

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
Griz answered 9/9, 2022 at 10:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.