JUnit XML

The JUnit XML format is a standardized output format for test results generated by test automation frameworks. It is widely used in continuous integration (CI) systems to record and visualize test results. Originally designed for the JUnit testing framework in Java, it is now supported by many testing tools across languages.

A test case is successful (passed) unless there is a different result element beneath it. Most tools recognize result elements such as skipped, failure, and error.

 

JUnit XML file example:

<?xml version="1.0" encoding="UTF-8"?> <testsuites id="" name="" tests="4" failures="2" skipped="1" errors="0" time="30.54786"> <testsuite name="example.spec.ts" timestamp="2024-11-25T12:12:42.765Z" hostname="chromium" tests="4" failures="2" skipped="1" time="36.873" errors="0"> <testcase name="Regression - Import test execution results by API 1 (no failure, no error=>passed)- Playwright" classname="example.spec.ts" time="0.95"> <properties> <property name="issue-key" value="QAREG-430"> </property> </properties> </testcase> <testcase name="Regression - Import test execution results by API 2 (failure) - Playwright" classname="example.spec.ts" time="5.899"> <properties> <property name="issue-key" value="ABC-584"> </property> </properties> <failure message="example.spec.ts:9:5 Regression - Import test execution results by API 2 (failure) - Playwright" type="FAILURE"> Error: Timed out 5000ms waiting for expect(locator).toHaveTitle(expected) </failure> </testcase> <testcase name="Regression - Import test execution results by API 4 (skipped=>default status)- Playwright" classname="example.spec.ts" time="0"> <properties> <property name="issue-key" value="ABC-123"> </property> </properties> <skipped> </skipped> </testcase> </testsuite> </testsuites>

 

Main elements and their description:

Element

Description

Element

Description

<testsuites> … <testsuites>

A collection of multiple test suites or test cases, typically representing a group of related tests. Often the root element of the JUnit XML.

ATTRIBUTES

name: The name of the overall test suites.

tests: The total number of test cases across all suites.

failures: The total number of test cases that failed.

time: Total time taken to execute all tests.

errors: The number of test cases that had errors.

optional:

id: Identifier of the test suite.

skipped: The total number of test cases that were skipped.

assertions: The number of assertions in this file.

CHILDREN: <testsuite>

<testsuite> … <testsuite>

A group of test cases that share a common setup or purpose, often corresponding to a specific module or functionality.

ATTRIBUTES

name: The name of the test suite.
tests: The number of test cases within the suite.
failures: Number of failed tests in the suite.
time: The total time taken to execute the suite, often represented as a float in seconds.

optional:

errors: Number of tests that threw errors.

timestamp: The timestamp of when the test suite was executed.
hostname: The hostname of the machine where the tests were run.
package: A logical grouping- package or module being tested.

skipped: Number of tests that were skipped. - it shows only when there are tests that has been skipped.

file: Source code file of this test suite.

CHILDREN: <testcase>, <properties>(optional), <system-out>(optional), <system-err>(optional)

<testcase> … <testcase>

An individual unit of testing that verifies a specific functionality or behavior of the application.

ATTRIBUTES

name: The name of the test case.
classname: The name of the class containing the test.
time: The duration of the test case execution.

optional:

file: Source code file of this test case.

line: Source code line number of this test case.

assertions: The number of assertions verified during test case execution.

CHILDREN: <failure>(optional), <error>(optional), <skipped>(optional), <properties>(optional), <system-out>(optional), <system-err>(optional)

<properties>…

</properties>

An optional element that contains <property> elements.

CHILDREN: <property>(optional)

<property>…

</property>

Used to represent environment variables, configuration settings, or metadata.

ATTRIBUTES

name: The name of the property.
value: The value of the property.

<failure>…

</failure>

Indicates a test case that failed.

ATTRIBUTES

optional:

message: A description of why the test failed.
CONTENT

The stack trace or error message.

<error>…

</error>

Usually Indicates a test case has failed cause of an unexpected error like a null pointer.

ATTRIBUTES

optional:

message: A description of why the test failed.
CONTENT

The stack trace or error message.

<skipped>…

</skipped>

Indicates a test case that was skipped.

ATTRIBUTES

optional:

message: A description of why the test was skipped.

CONTENT

optional:

Details about why the test was skipped.

<system-out>…

</system-out>

 

<system-err>…

</system-err>

Captures data written to standard out or standard error for the test suite/test case.

CONTENT:

Captured data.

Â