Latest sneak peek about Importing JUnit XML reports
JUnit is used massively in the Java world but not only. In fact, many testing frameworks are using JUnit XML reports as the “de facto standard” report format.
Xray for JIRA now gives you the possibility to import those JUnit test results into JIRA.
You can directly import your JUnit results using the REST API or the Import Execution Results button from the Test Execution screen.
How it works
Lets start looking at JUnit’s XML format.
The simplified tag hierarchy of these type of reports can be represented in the following diagram:
Below is a simplified example of a JUnit XML report, containing a Test Suite with 2 Test Cases (one failing and one passing).
The Test Cases are imported to Xray’s Generic Test issues, and the “name” and “classname” attributes are concatenated and mapped to the “Generic Test Definition” field of the Generic Test.
If a Test already exists with the same “Generic Test Definition”, then it is not created again, although its execution result will be set in the created/updated Test Execution.
The Test Run status will be set based on each Test Case result.
Test Case Result Statuses
The Test case result may have the following statuses, which will be mapped in Xray as follows:
Test Run Overall Statuses
If a Test has more than one context, then the overall execution status may be calculated as:
Importing JUnit Results
There are two ways of importing results to JIRA:
- By using the Import Executions Results button on a Test Execution;
- By using the REST API.
Import JUnit Results using the Import Execution Results button
JUnit Test results can be imported back to JIRA, through the Test Execution view issue screen.
To import JUnit Test results to a Test Execution issue containing automated Tests, the following steps must be taken:
1) Open the Test Execution issue view page;
2) Select More > Import Execution Results;
3) The Import Execution Results dialog will be prompted;
4) Click on the Choose Filebutton to navigate to your local disk and select the XML file with the JUnit execution results for the Test Execution
Import JUnit Results using the REST API
To import JUnit XML reports using the REST API, you must use the following endpoint
Refer to the Request Parameters described on the following table to parameterize your REST call accordingly:
Required parameters: (projectKey or testExecKey) + file
Examples of usage
- curl -H “Content-Type: multipart/form-data” -u admin:admin -F “[email protected]” “http://yourserver/rest/raven/1.0/import/execution/junit?projectKey=XTP”
- curl -H “Content-Type: multipart/form-data” -u admin:admin -F “[email protected]” “http://yourserver/rest/raven/1.0/import/execution/junit?testExecKey=XNP-23”
- curl -H “Content-Type: multipart/form-data” -u admin:admin -F “[email protected]” “http://yourserver/rest/raven/1.0/import/execution/junit?projectKey=XTP&testExecKey=XNP-23”
- curl -H “Content-Type: multipart/form-data” -u admin:admin -F “[email protected]” “http://yourserver/rest/raven/1.0/import/execution/junit?projectKey=XTP&testPlanKey=XTX-12&revision=v2.1.0&testEnvironments=windows;chrome”
As an example, we’ll be using the Junit XML report file presented in the first section.
Two new tests were created in JIRA, and the Test Execution issue was updated with the association of these tests as well.
As we have one test failing, we are going to check its Execution Details by accessing the Execution page of that Test Run:
The Results section displays all the relevant information about the execution: The Test Suite context, the error message, the duration and the status of that particular test.
JUnit XML reports can now be interpreted by Xray giving you the possibility to have an overview of all your automated tests. It’s never been so easy to know if all your automated tests are passing or not. You can easily integrate your CI builds to report automated test results using the REST API.
The import of Nunit (v2.6 and v3.0) and Robot XML reports will also be included in this version, meaning that Xray 2.1 is a step ahead in the import of automated test results into JIRA.