quick_junit/
lib.rs

1// Copyright (c) The nextest Contributors
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4#![warn(missing_docs)]
5
6//! `quick-junit` is a JUnit/XUnit XML data model and serializer for Rust. This crate allows users
7//! to create a JUnit report as an XML file. JUnit XML files are widely supported by test tooling.
8//!
9//!  This crate is built to serve the needs of [cargo-nextest](https://nexte.st).
10//!
11//! # Overview
12//!
13//! The root element of a JUnit report is a [`Report`]. A [`Report`] consists of one or more
14//! [`TestSuite`] instances. A [`TestSuite`] instance consists of one or more [`TestCase`]s.
15//!
16//! The status (success, failure, error, or skipped) of a [`TestCase`] is represented by
17//! [`TestCaseStatus`].
18//!
19//! # Features
20//!
21//! - ✅ Serializing JUnit/XUnit to the [Jenkins format](https://llg.cubic.org/docs/junit/).
22//! - ✅ Including test reruns using [`TestRerun`]
23//! - ✅ Including flaky tests
24//! - ✅ Including standard output and error
25//!   - ✅ Filtering out [invalid XML
26//!     characters](https://en.wikipedia.org/wiki/Valid_characters_in_XML) (eg ANSI escape codes)
27//!     from the output
28//! - ✅ Automatically keeping track of success, failure and error counts
29//! - ✅ Arbitrary properties and extra attributes
30//!
31//! This crate does not currently support deserializing JUnit XML. (PRs are welcome!)
32//!
33//! # Examples
34//!
35//! ```rust
36//! use quick_junit::*;
37//!
38//! let mut report = Report::new("my-test-run");
39//! let mut test_suite = TestSuite::new("my-test-suite");
40//! let success_case = TestCase::new("success-case", TestCaseStatus::success());
41//! let failure_case = TestCase::new("failure-case", TestCaseStatus::non_success(NonSuccessKind::Failure));
42//! test_suite.add_test_cases([success_case, failure_case]);
43//! report.add_test_suite(test_suite);
44//!
45//! const EXPECTED_XML: &str = r#"<?xml version="1.0" encoding="UTF-8"?>
46//! <testsuites name="my-test-run" tests="2" failures="1" errors="0">
47//!     <testsuite name="my-test-suite" tests="2" disabled="0" errors="0" failures="1">
48//!         <testcase name="success-case">
49//!         </testcase>
50//!         <testcase name="failure-case">
51//!             <failure/>
52//!         </testcase>
53//!     </testsuite>
54//! </testsuites>
55//! "#;
56//!
57//! assert_eq!(report.to_string().unwrap(), EXPECTED_XML);
58//! ```
59//!
60//! For a more comprehensive example, including reruns and flaky tests, see
61//! [`fixture_tests.rs`](https://github.com/nextest-rs/quick-junit/blob/main/tests/fixture_tests.rs).
62//!
63//! # Minimum supported Rust version (MSRV)
64//!
65//! The minimum supported Rust version is **Rust 1.70.** At any time, Rust versions from at least
66//! the last 6 months will be supported.
67//!
68//! While this crate is a pre-release (0.x.x) it may have its MSRV bumped in a patch release. Once a
69//! crate has reached 1.x, any MSRV bump will be accompanied with a new minor version.
70//!
71//! # Alternatives
72//!
73//! - [**junit-report**](https://crates.io/crates/junit-report): Older, more mature project. Doesn't
74//!   appear to support flaky tests or arbitrary properties as of version 0.8.3.
75
76mod errors;
77mod report;
78mod serialize;
79
80pub use errors::*;
81pub use report::*;