#junit #report #xml #xml-format #xunit

junit-report

Create JUnit compatible XML reports

17 releases

0.8.3 Oct 23, 2023
0.8.2 Dec 16, 2022
0.8.1 Sep 10, 2022
0.7.1 Apr 27, 2022
0.1.2 Nov 22, 2018

#47 in Testing

Download history 13922/week @ 2023-12-06 14607/week @ 2023-12-13 9356/week @ 2023-12-20 5982/week @ 2023-12-27 12905/week @ 2024-01-03 13802/week @ 2024-01-10 16339/week @ 2024-01-17 15412/week @ 2024-01-24 13541/week @ 2024-01-31 14276/week @ 2024-02-07 15302/week @ 2024-02-14 15761/week @ 2024-02-21 17545/week @ 2024-02-28 16146/week @ 2024-03-06 16715/week @ 2024-03-13 12484/week @ 2024-03-20

65,968 downloads per month
Used in 13 crates (10 directly)

MIT license

38KB
746 lines

JUnit Report in Rust

Generate JUnit compatible XML reports in Rust.

Example


    use junit_report::{datetime, Duration, ReportBuilder, TestCase, TestCaseBuilder, TestSuite, TestSuiteBuilder};
    use std::fs::File;

    // Create a successful test case
    let test_success = TestCaseBuilder::success("good test", Duration::seconds(15))
        .set_classname("MyClass")
        .set_filepath("MyFilePath")
        .build();

    // Create a test case that encountered an unexpected error condition
    let test_error = TestCase::error(
        "error test",
        Duration::seconds(5),
        "git error",
        "unable to fetch",
    );

    // Create a test case that failed because of a test failure
    let test_failure = TestCase::failure(
        "failure test",
        Duration::seconds(10),
        "assert_eq",
        "not equal",
    );

    // Next we create a test suite named "ts1" with not test cases associated
    let ts1 = TestSuite::new("ts1");

    // Then we create a second test suite called "ts2" and set an explicit time stamp
    // then we add all the test cases from above
    let timestamp = datetime!(1970-01-01 00:01:01 UTC);
    let ts2 = TestSuiteBuilder::new("ts2")
        .set_timestamp(timestamp)
        .add_testcase(test_success)
        .add_testcase(test_error)
        .add_testcase(test_failure)
        .build();

    // Last we create a report and add all test suites to it
    let r = ReportBuilder::new()
        .add_testsuite(ts1)
        .add_testsuite(ts2)
        .build();

    // The report can than be written in XML format to any writer
    let mut file = File::create("my-junit.xml").unwrap();
    r.write_xml(&mut file).unwrap();

Dependencies

~3.5MB
~72K SLoC