Skip to main content

junit_export/
junit_export.rs

1//! Build a sample `Report`, export it as JUnit XML, and print to stdout.
2//!
3//! Requires the `junit` feature:
4//!
5//! ```text
6//! cargo run --example junit_export --features junit > report.junit.xml
7//! ```
8//!
9//! Demonstrates the verdict-to-element mapping: pass and warn produce
10//! self-closing `<testcase>`, fail produces `<failure>` children, skip
11//! produces `<skipped/>` children. Durations propagate as `time`
12//! attributes in seconds.
13
14use dev_report::{CheckResult, Report, Severity};
15
16fn main() {
17    let mut r = Report::new("sample-subject", "0.9.3").with_producer("dev-bench");
18
19    r.push(CheckResult::pass("compile").with_duration_ms(120));
20    r.push(CheckResult::pass("test::math").with_duration_ms(7));
21
22    r.push(
23        CheckResult::fail("test::round_trip", Severity::Error)
24            .with_duration_ms(13)
25            .with_detail("expected 42, got 41"),
26    );
27
28    r.push(
29        CheckResult::fail("integration::startup", Severity::Critical)
30            .with_detail("service refused to start"),
31    );
32
33    r.push(
34        CheckResult::warn("style::trailing_ws", Severity::Warning)
35            .with_detail("3 trailing-whitespace warnings"),
36    );
37
38    r.push(CheckResult::skip("integration::network").with_detail("no network in sandbox"));
39
40    r.finish();
41
42    println!("{}", r.to_junit_xml());
43}