#junit #xml #serialization #data-model #xml-data #xml-format

quick-junit

Data model and serializer for JUnit/XUnit XML

18 releases

0.5.1 Nov 18, 2024
0.4.0 Apr 19, 2024
0.3.5 Oct 27, 2023
0.3.3 Jul 7, 2023
0.1.5 Feb 13, 2022

#105 in Encoding

Download history 14501/week @ 2024-08-16 17920/week @ 2024-08-23 17057/week @ 2024-08-30 19924/week @ 2024-09-06 20120/week @ 2024-09-13 23733/week @ 2024-09-20 22929/week @ 2024-09-27 24034/week @ 2024-10-04 21912/week @ 2024-10-11 21475/week @ 2024-10-18 24878/week @ 2024-10-25 23682/week @ 2024-11-01 34503/week @ 2024-11-08 38761/week @ 2024-11-15 35068/week @ 2024-11-22 36518/week @ 2024-11-29

151,001 downloads per month
Used in 23 crates (9 directly)

Apache-2.0 OR MIT

52KB
949 lines

quick-junit

quick-junit on crates.io Documentation (latest release) Documentation (main) Changelog License License

quick-junit is a JUnit/XUnit XML data model and serializer for Rust. This crate allows users to create a JUnit report as an XML file. JUnit XML files are widely supported by test tooling.

This crate is built to serve the needs of cargo-nextest.

Overview

The root element of a JUnit report is a Report. A Report consists of one or more TestSuite instances. A TestSuite instance consists of one or more TestCases.

The status (success, failure, error, or skipped) of a TestCase is represented by TestCaseStatus.

Features

  • ✅ Serializing JUnit/XUnit to the Jenkins format.
  • ✅ Including test reruns using TestRerun
  • ✅ Including flaky tests
  • ✅ Including standard output and error
  • ✅ Automatically keeping track of success, failure and error counts
  • ✅ Arbitrary properties and extra attributes

This crate does not currently support deserializing JUnit XML. (PRs are welcome!)

Examples

use quick_junit::*;

let mut report = Report::new("my-test-run");
let mut test_suite = TestSuite::new("my-test-suite");
let success_case = TestCase::new("success-case", TestCaseStatus::success());
let failure_case = TestCase::new("failure-case", TestCaseStatus::non_success(NonSuccessKind::Failure));
test_suite.add_test_cases([success_case, failure_case]);
report.add_test_suite(test_suite);

const EXPECTED_XML: &str = r#"<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="my-test-run" tests="2" failures="1" errors="0">
    <testsuite name="my-test-suite" tests="2" disabled="0" errors="0" failures="1">
        <testcase name="success-case">
        </testcase>
        <testcase name="failure-case">
            <failure/>
        </testcase>
    </testsuite>
</testsuites>
"#;

assert_eq!(report.to_string().unwrap(), EXPECTED_XML);

For a more comprehensive example, including reruns and flaky tests, see fixture_tests.rs.

Minimum supported Rust version (MSRV)

The minimum supported Rust version is Rust 1.70. At any time, Rust versions from at least the last 6 months will be supported.

While this crate is a pre-release (0.x.x) it may have its MSRV bumped in a patch release. Once a crate has reached 1.x, any MSRV bump will be accompanied with a new minor version.

Alternatives

  • junit-report: Older, more mature project. Doesn't appear to support flaky tests or arbitrary properties as of version 0.8.3.

Contributing

See the CONTRIBUTING file for how to help out.

License

This project is available under the terms of either the Apache 2.0 license or the MIT license.

Dependencies

~4.5MB
~78K SLoC