#junit #xml #report #xunit

junit-report

Create JUnit compatible XML reports

11 unstable releases (5 breaking)

new 0.6.0 Jul 20, 2021
0.4.2 May 28, 2021
0.4.1 Mar 2, 2021
0.4.0 Jun 4, 2020
0.1.2 Nov 22, 2018

#26 in Testing

Download history 1531/week @ 2021-04-03 1332/week @ 2021-04-10 1399/week @ 2021-04-17 1422/week @ 2021-04-24 1345/week @ 2021-05-01 1081/week @ 2021-05-08 1246/week @ 2021-05-15 1204/week @ 2021-05-22 1206/week @ 2021-05-29 1390/week @ 2021-06-05 1568/week @ 2021-06-12 2080/week @ 2021-06-19 2079/week @ 2021-06-26 2358/week @ 2021-07-03 2548/week @ 2021-07-10 2144/week @ 2021-07-17

6,982 downloads per month
Used in 4 crates

MIT license

33KB
652 lines

JUnit Report in Rust

Generate JUnit compatible XML reports in Rust.

Example


    extern crate junit_report;

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

    // Create a successful test case
    let test_success = TestCaseBuilder::success("good test", Duration::seconds(15))
        .set_classname("MyClass")
        .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 = Utc.ymd(1970, 1, 1).and_hms(0, 1, 1);
    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

~1.3–1.9MB
~37K SLoC