Skip to main content
Skip table of contents

JUnit XML report

About JUnit

image-20241121-062241.png

JUnit is a unit testing open-source framework for the Java programming language. Java Developers use this framework to write and execute automated tests. In Java, there are test cases that have to be re-executed every time a new code is added. Though this framework has been implemented originally for Java, its XML report formatted file could be generated by many test frameworks from different programming languages.

Common structure

In a basic JUnit report, you should find common tags depicting test suites and test cases.

JUnit report example
XML
<testsuites id="" name="" tests="2" failures="0" skipped="0" errors="0" time="2.07591">
	<testsuite name="example.spec.ts" timestamp="2024-04-05T09:57:40.026Z" hostname="chromium" tests="2" failures="0" skipped="0" time="2.651" errors="0">
		<testcase name="has title" classname="example.spec.ts" time="1.13"></testcase>
		<testcase name="get started link" classname="example.spec.ts" time="1.521"></testcase>
	</testsuite>
</testsuites>

To visualize the structure more clearly, let’s take a look at the diagram below.

JUnit test report structure diagram

JUnit test report structure diagram

How AgileTest would parse a JUnit report

In AgileTest, all test cases imported using the automation feature are categorized as Generic Tests.

Imported test cases are distinguished by the classname and name attributes parsed from the XML file. The combination of these attributes is referred to as the Test Definition in AgileTest. Users can find the Test Definition located just below the Description area of the test case tickets. The Summary of each test case issue corresponds to the value of the name attribute.

Supported status tags

Test run status tag

Description

<pass>, <passed> or no tag

PASSED → Test case yields the expected result.

<failure>

FAILED → Test case returns the actual result not as expected.

<blocked>

BLOCKED → Test case is considered blocked due to a specific reason.

<skipped>

SKIPPED → Test case is skipped in the test run.

<retest>

RETEST → Test case should be rerun again.

<query>

QUERY → Test case requires more details to have the final result.

<todo>, <to do>, or non-defined statuses

TODO → Test case is not yet run. It’s the default status of every Test case in AgileTest.

The priority of status tags in AgileTest follows this order: failed > blocked > retest > skipped > query > passed (or no tag).

If multiple tags are added to a single <testcase> element, the tag with the highest priority will be parsed as the test status in AgileTest.

Test result without steps

Test suite is a group of Test cases. Many Test suites are grouped inside a <testsuites> element.

The context information will be reflected, each row shows result of each time the script rerun the test. Let’s take a look at the example below.

The result will be displayed in Context section.

  • Context name is constituted by “TestSuite” and name attribute of <testsuite> element.

  • Test run status will be parsed accordingly following the mentioned rule.

  • Duration is the duration value of <testcase> element.

  • Status is the status value of <testcase> element.

JUnit report example

XML
<testsuites id="" name="" tests="2" failures="1" skipped="0" errors="0" time="6.707531">
    <testsuite name="check context" timestamp="2024-01-23T03:45:35.369Z" hostname="chromium" tests="2" failures="1" skipped="0" time="7.768" errors="0">
        <testcase name="Login with common user's credentials" classname="example.spec.ts" time="6.161">
        </testcase>
        <testcase name="Add items to cart" classname="example.spec.ts" time="1.607">
            <failure message="Assertion error message" type="AssertionError">
                <!-- Call stack printed here -->
            </failure> 
        </testcase>
    </testsuite>
</testsuites>

Context information parsed from test report

Test result with steps

As you may know, the default JUnit report format does not support test steps. However, the community has made customizations using the <property> element to store test steps in the report. AgileTest also recognizes and supports this customization for better test result management.

Elements would be parsed similarly to Test result without steps, but with some enhancements.

  • Context name is constituted by “TestSuite” and name attribute of <testsuite> element.

  • Test run status will be parsed accordingly following the mentioned rule.

  • Duration is the duration value of <testcase> element.

  • Step status is based on the text inside the square brackets (case insensitive)

Test step status property

Description

[pass] or [passed]

PASSED → Test step returns the expected outcome.

[fail], [failed], or [error]

FAILED → Test step yields wrong result.

[blocked]

BLOCKED → Test step is blocked due to a certain reason.

[skipped]

SKIPPED → Test step is skipped.

[retest]

RETEST → Test step is due to rerun again.

[query]

QUERY → Test step requires more information.

[todo], [to do], or non-defined statuses

TODO → Test step is marked to do, which is the default status of step status.

Test result with attachments

Attachments are also part of the customization supported in AgileTest. However, unlike test steps, attachments are included in the test report as elements (or tags).

There are 3 ways to include attachments in your test report:

1. Default attachment structure of JUnit

Some frameworks generate attachments and store them in the test report with the structure as below.

Element structure
XML
<system-out>
  <![CDATA[
  [[ATTACHMENT|file path or base64 content]]
  ]]>
</system-out>
Example
XML
<testcase>
  <system-out>
    <![CDATA[
    [[ATTACHMENT|test-failed-1.png]]
    ]]>
  </system-out>
</testcase>

2. Attachment element with name attribute and content inside

Element structure
XML
<attachment name="filename"> base64 content </attachment>
Example
XML
<testcase>
  ....
  <attachments>
    <attachment name="test.png">iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAQ0lEQVR42u3PQREAAAgDINc/9Mzg14MGZNrOAxERERERERERERERERERERERERERERERERERERERERERERERERERuVh9TJWdbWjzsQAAAABJRU5ErkJggg==</attachment>
  </attachments>
</testcase>

3. Attachment element with separate name and content elements inside

Element structure
XML
<attachment> 
  <name>filename</name>
  <rawcontent> base64 content </rawcontent>
</attachment>
Example
XML
<testcase>
  ....
  <attachments>
    <attachment> 
      <name>test.png</name>
      <rawcontent>iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAQ0lEQVR42u3PQREAAAgDINc/9Mzg14MGZNrOAxERERERERERERERERERERERERERERERERERERERERERERERERERuVh9TJWdbWjzsQAAAABJRU5ErkJggg==</rawcontent>
    </attachment>
  </attachments>
</testcase>


Should you need any assistance or further AgileTest inquiries, please contact us here!

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.