Junit reference


Tuskr integrates seamlessly with all the popular automation tools and CI/CD frameworks. You can use our API or our CLI (command line interface) program.

We import result data including file attachments and create and update test cases on the fly. Furthermore, we enable you to set test case meta-data including your custom fields using declarative rules i.e. without writing code - for example, set test case type to Performance if class name has ".performance" in it. This way you can slice and dice data in a way that makes the most sense for your team.

Also, if you are using TestRail or Xray, we import those JUnit XML files in their format, making it easy for you to try Tuskr.

What is a JUnit XML file?

A JUnit XML file is a type of XML file used to store test results generated by testing frameworks compatible with JUnit, one of the most popular unit testing frameworks in the Java ecosystem. This file format is often used for generating reports and integrating with various CI/CD tools.

What is the structure of this file?

The JUnit XML file typically follows a structured format that includes details about test suites, test cases, and their outcomes. The basic structure includes:

  • <testsuites>: The root element which can contain one or more <testsuite> elements.
  • <testsuite>: Represents a test suite and contains several <testcase> elements. Attributes include name, number of tests, failures, etc.
  • <testcase>: Represents a single test case. Attributes include name, classname, and time taken to execute.
  • <failure> (optional): Nested within <testcase>, indicates a test failure. Attributes usually include a message and type.
Sample JUnit XML File
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
    <testsuite name="SampleTestSuite" tests="2" failures="1" skipped="0" time="0.003">
        <testcase classname="example.SampleTest" name="testOne" time="0.001" />
        <testcase classname="example.SampleTest" name="testTwo" time="0.002">
            <failure message="Test failed due to condition X" type="AssertionError">
            Failure details...
            </failure>
        </testcase>
    </testsuite>
</testsuites>

This example illustrates a simple JUnit XML file with one test suite containing two test cases, where one test case passed, and the other failed. This file format is essential for analyzing test results and can be used for integration with various tools and services.

Tuskr CLI Tool - Entity Mapping

JUnit XML Entity Tuskr Entity
testsuites name attribute Test Suite in Tuskr
testsuite name attribute Test Suite Section in Tuskr
testcase name attribute Test Case in Tuskr
property tag within testcase tag Property of Test Case in Tuskr

Customizing Test Case Properties

Users can customize test case properties in Tuskr by utilizing the <property> tags within XML files. Here's how this process works:

  • All <property> tags within the <properties> tags, which are present inside a <testcase> tag, will be considered for updating the attributes of that test case in Tuskr.
  • The value attribute of the <property> tag will be used as the actual value in Tuskr.
  • To update a test case field, the name attribute should be in the format name=testCase[key], where "key" could be the key of a system field or a custom field. For a custom field key, prepend custom_ to the key.
  • To update the result fields for the test case, use the format name=result[key]. Again, "key" can be either a system or a custom field key, with custom fields having custom_ prefixed.
  • If the name attribute is name=result[attachment], it will be treated as an attachment for the result. The value for this property tag should be the name/path of the attachment.

Here is a sample XML snippet demonstrating the use of property tags:

  <testcase classname="test_sample.test_parameter" name="test_example_performance" time="0.002">
      <properties>
          <property name="testCase[custom_celoxismodule]" value="Projects, Tasks" />
          <property name="testCase[custom_automation_status]" value="Automated" />
          <property name="result[attachment]" value="error.txt" />
          <property name="result[custom_csv_test_multi_select]" value="error.txt" />
          <property name="result[timeSpentInMinutes]" value="20" />
      </properties>
  </testcase>

This sample shows how various attributes of a test case, including custom fields and attachments, can be updated in Tuskr through the use of properly formatted property tags in a JUnit XML file.

Specifying Attachments in Results

To include attachments for test results in a JUnit XML file when using the Tuskr CLI tool, users should follow these guidelines:

  • A <property> tag with a specific format is used to indicate an attachment. The name attribute should be exactly result[attachment], and the value should be the name or relative path of the attachment file.
  • If the attachment files are located in a directory different from where the XML file is, the --attachments-path option should be used to specify the relative path of the directory containing the attachments. This path will be used by the command to locate all the mentioned attachments in the XML file.

Here is a sample XML snippet demonstrating how to specify an attachment:

  <testcase classname="test_sample.test_parameter" name="test_example_performance" time="0.002">
      <properties>
          <property name="result[attachment]" value="error.txt" />
      </properties>
  </testcase>

In this example, error.txt is treated as an attachment for the test result. The file error.txt should be located in the same directory as the XML file or in a directory specified by the --attachments-path option when running the Tuskr CLI command.