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//! - ✅ Deserializing JUnit/XUnit XML back to Rust data structures
23//! - ✅ Including test reruns using [`TestRerun`]
24//! - ✅ Including flaky tests
25//! - ✅ Including standard output and error
26//!   - ✅ Filtering out [invalid XML
27//!     characters](https://en.wikipedia.org/wiki/Valid_characters_in_XML) (eg ANSI escape codes)
28//!     from the output
29//! - ✅ Automatically keeping track of success, failure and error counts
30//! - ✅ Arbitrary properties and extra attributes
31//!
32//! # Examples
33//!
34//! ```rust
35//! use quick_junit::*;
36//!
37//! let mut report = Report::new("my-test-run");
38//! let mut test_suite = TestSuite::new("my-test-suite");
39//! let success_case = TestCase::new("success-case", TestCaseStatus::success());
40//! let failure_case = TestCase::new("failure-case", TestCaseStatus::non_success(NonSuccessKind::Failure));
41//! test_suite.add_test_cases([success_case, failure_case]);
42//! report.add_test_suite(test_suite);
43//!
44//! const EXPECTED_XML: &str = r#"<?xml version="1.0" encoding="UTF-8"?>
45//! <testsuites name="my-test-run" tests="2" failures="1" errors="0">
46//!     <testsuite name="my-test-suite" tests="2" disabled="0" errors="0" failures="1">
47//!         <testcase name="success-case">
48//!         </testcase>
49//!         <testcase name="failure-case">
50//!             <failure/>
51//!         </testcase>
52//!     </testsuite>
53//! </testsuites>
54//! "#;
55//!
56//! assert_eq!(report.to_string().unwrap(), EXPECTED_XML);
57//! ```
58//!
59//! For a more comprehensive example, including reruns and flaky tests, see
60//! [`fixture_tests.rs`](https://github.com/nextest-rs/quick-junit/blob/main/tests/fixture_tests.rs).
61//!
62//! # Optional features
63//!
64//! - **proptest**: Generate `Arbitrary` instances for use with proptest. *Not enabled by default.*
65//!
66//! # Minimum supported Rust version (MSRV)
67//!
68//! The minimum supported Rust version is **Rust 1.70.** At any time, Rust versions from at least
69//! the last 6 months will be supported.
70//!
71//! While this crate is a pre-release (0.x.x) it may have its MSRV bumped in a patch release. Once a
72//! crate has reached 1.x, any MSRV bump will be accompanied with a new minor version.
73//!
74//! # Alternatives
75//!
76//! - [**junit-report**](https://crates.io/crates/junit-report): Older, more mature project. Doesn't
77//!   appear to support flaky tests or arbitrary properties as of version 0.8.3.
78
79mod deserialize;
80mod errors;
81mod report;
82mod serialize;
83
84#[cfg(any(test, feature = "proptest"))]
85mod proptest_impls;
86
87pub use errors::*;
88pub use report::*;