junit-10.xsd
Overview
The [junit-10.xsd](/projects/286/67223) file is an XML Schema Definition (XSD) that defines the structure and constraints of XML reports produced by JUnit testing frameworks, specifically aligned with the Surefire report format used in Maven and other build tools. This schema ensures that test result XML files conform to a standardized format, allowing tools and systems to reliably parse, validate, and process test results.
The schema defines the elements, attributes, data types, and hierarchical relationships for test suites, test cases, and their outcomes such as failures, errors, skipped tests, and reruns. It supports backward compatibility with older Surefire versions through optional elements and mixed content types.
Detailed Description of Elements and Types
Simple Types
SUREFIRE_TIME
Type: xs:string with pattern restriction
Pattern:
(([0-9]{0,3},)*[0-9]{3}|[0-9]{0,3})*(\.[0-9]{0,3})?Purpose: Represents time durations in a specific numeric format that may include commas as thousand separators and up to three decimal places.
Usage: Used for time-related attributes such as the duration of test cases or test suites.
Complex Types
rerunType
Description: Represents details for rerun failures or errors in test cases. It supports mixed content (text + elements) for backward compatibility with Surefire versions prior to 2.22.1.
Elements:
stackTrace (optional, string): The stack trace of the rerun failure/error.
system-out(optional, string): Captured standard output during rerun.system-err(optional, string): Captured standard error output during rerun.
Attributes:
message(string, optional): Message describing the rerun failure/error.type(string, required): The type or category of the rerun failure/error.
Usage: Used for elements such as
<rerunFailure>,<rerunError>,<flakyFailure>, and<flakyError>.
Elements
failure
Type: Complex type with mixed content.
Attributes:
type(string, optional): The failure type, e.g., exception class.message(string, optional): Failure message.
Usage: Represents a test failure within a test case.
error
Type: Complex type with mixed content.
Attributes:
type(string, optional): The error type.message(string, optional): Error message.
Usage: Represents a test error within a test case.
skipped
Type: Complex type with mixed content.
Attributes:
type(string, optional): The reason or type for skipping.message(string, optional): Message describing why the test was skipped.
Usage: Represents skipped tests.
properties
Type: Complex type containing zero or more
propertyelements.Usage: Used to encapsulate key-value pairs describing environment or configuration properties relevant to the test suite or test case.
property
Attributes:
name(string, required): The key/name of the property.value (string, required): The value associated with the property.
Usage: Defines individual properties.
system-out and system-err
Type: Simple string elements.
Usage: Capture standard output and error output respectively, often used within
testcaseortestsuite.
rerunFailure, rerunError, flakyFailure, flakyError
Type:
rerunTypeUsage: Represent rerun or flaky test failures/errors with detailed reporting.
testcase
Type: Complex type.
Elements: Zero or more of the following (in any order):
skippederrorfailurererunFailure(0..*)rerunError(0..*)flakyFailure(0..*)flakyError(0..*)system-outsystem-err
Attributes:
name(string, required): Name of the test case.time(string, optional): Duration of the test case execution.classname(string, optional): Name of the class containing the test.group (string, optional): Group or category to which the test belongs.
Usage: Represents a single test case including its outcome and outputs.
testsuite
Type: Complex type.
Elements: Zero or more of the following:
Nested
testsuiteelements (allowing hierarchical test suites)propertiestestcasesystem-outsystem-err
Attributes:
name(string, required): Name of the test suite.tests(string, required): Total number of tests.failures (string, required): Number of failed tests.
errors (string, required): Number of tests with errors.
Optional attributes such as group,
time(using SUREFIRE_TIME),skipped,timestamp,hostname,id,package,file,log,url,version.
Usage: Represents a collection of test cases, possibly nested test suites, and related metadata.
testsuites
Type: Complex type.
Elements: Zero or more
testsuiteelements.Attributes:
Usage: Root element for multiple test suite results.
Important Implementation Details
The schema supports backward compatibility by allowing mixed content in certain elements such as
rerunTypeandfailure, accommodating text alongside child elements.Test suites can be nested recursively to represent hierarchical test structures.
The SUREFIRE_TIME type enforces a specific numeric format for time durations, ensuring consistency.
The use of optional elements and attributes allows flexible reporting adapting to various testing scenarios and versions.
The schema separates concerns by distinctly defining rerun and flaky failures/errors, supporting advanced testing scenarios like flaky test detection and retries.
Properties enable embedding arbitrary key-value metadata, enriching the test report context.
Interaction with Other Parts of the System
JUnit/Surefire Test Report Generation: This schema is primarily used by test execution frameworks (e.g., Maven Surefire plugin) to generate XML reports in a standard format.
CI/CD Systems and Test Report Parsers: Continuous integration tools and dashboards parse XML files validated against this schema to display test results, trends, and analytics.
Test Result Aggregators and Analyzers: Tools that aggregate multiple test results or perform test flakiness analysis rely on this schema for consistent input.
Backward Compatibility: Older versions of Surefire or test frameworks that produce similar XML reports can still be validated due to the flexible schema design.
Usage Example
A snippet of a test case element conforming to this schema could look like:
<testcase name="testAddition" classname="com.example.CalculatorTest" time="0.123">
<failure type="AssertionError" message="Expected 4 but got 5">...</failure>
<system-out>Test output here</system-out>
<system-err></system-err>
</testcase>
Visual Diagram
flowchart TD
Testsuites["testsuites"]
Testsuite["testsuite"]
Testcase["testcase"]
Properties["properties"]
Property["property"]
Failure["failure"]
Error["error"]
Skipped["skipped"]
RerunType["rerunType"]
RerunFailure["rerunFailure"]
RerunError["rerunError"]
FlakyFailure["flakyFailure"]
FlakyError["flakyError"]
SystemOut["system-out"]
SystemErr["system-err"]
Testsuites -->|contains| Testsuite
Testsuite -->|contains| Testsuite
Testsuite -->|contains| Properties
Testsuite -->|contains| Testcase
Testsuite -->|contains| SystemOut
Testsuite -->|contains| SystemErr
Properties -->|contains| Property
Testcase -->|may contain any of| Skipped
Testcase -->|may contain any of| Error
Testcase -->|may contain any of| Failure
Testcase -->|may contain multiple| RerunFailure
Testcase -->|may contain multiple| RerunError
Testcase -->|may contain multiple| FlakyFailure
Testcase -->|may contain multiple| FlakyError
Testcase -->|may contain| SystemOut
Testcase -->|may contain| SystemErr
RerunFailure -.-> RerunType
RerunError -.-> RerunType
FlakyFailure -.-> RerunType
FlakyError -.-> RerunType
Summary
The [junit-10.xsd](/projects/286/67223) file defines a comprehensive XML schema for JUnit test reports, especially aligned with Maven Surefire output. It enables structured, validated representation of test suites, cases, and their results including complex scenarios like reruns and flaky tests. This schema plays a crucial role in the testing and CI/CD ecosystem by standardizing test result data exchange and enabling reliable integration with reporting and analysis tools.