Automating the import of test results into the RTM app simplifies your testing process by integrating test execution data directly into your test management system. This section explains how to use the REST API of the RTM app to import test results and integrate this process into your Continuous Integration (CI) pipelines.
To import test results into the Requirements and Test Management app, upload a XML files in JUnit format. Once uploaded, the steps below will create a Test Execution with Test Case Executions based on the imported results.
If you aren’t sure how to create a XML file for the import, download the sample file.
As Continuous Integration (CI) and Continuous Delivery (CD) practices become increasingly widespread, automated testing has emerged as a critical component of the software development lifecycle. This evolution is expected, given the significant advantages automated tests offer over manual testing:
Automated tests are written as code, whether in compiled languages like Java or interpreted ones like Python, and are typically integrated into the Continuous Integration (CI) pipeline. These tests run automatically upon code commits or at scheduled intervals, ensuring consistent execution and immediate results. This integration fosters rapid feedback loops and continuous improvement throughout the development process.
To interact with the RTM API, authenticate your requests with an API token. This section explains how to generate an API token within the RTM application.
If you already have an API token then you can use it to import test results and skip this step.
Copy the API token right away. For security reasons, you won’t be able to display it again after closing the modal. Store the token securely, as you need it to authenticate your API requests.
You have created an API Token that can be used in API requests. When making API calls to the RTM app, include the token in the Authorization header as a Bearer token.
Here is the example header:
Authorization: Bearer YOUR_API_TOKEN
Replace YOUR_API_TOKEN with the generated Token.
To access the base URL for the RTM API:
Importing test results requires calling the RTM REST API with zip or tar.gz file that contains test results files and valid Jira project key with enabled RTM.
Example of the import using curl
curl -X POST 'https://your-rtm-instance.com/api/v2/automation/import-test-results' \
-H 'Authorization: Bearer YOUR_API_TOKEN' \
-F 'projectKey=RTM_PROJECT_KEY' \
-F 'name=Example automated test execution'
-F 'file=@/path/to/test-results.tar.gz' \
-F 'reportType=JUNIT' \
-F 'jobUrl=https://ci.example.com/job/123'
See REST API for all available options for import endpoint
Use the API Token in a Python Script that sends a test report to the RTM API.
import requests
import json
# RTM API endpoint for importing test results
url = 'https://your-rtm-instance.com/api/v2/automation/import-test-results'
# Replace 'YOUR_API_TOKEN' with the API token you generated
headers = {
'Authorization': 'Bearer YOUR_API_TOKEN'
}
# Define the test execution fields
test_execution_fields = {
"fields": {
"summary": "Automated Test Execution",
"description": "Imported from CI"
}
}
# Path to the ZIP file containing test results
test_results_zip_path = '/path/to/test-results.zip' # Update with the actual path
# Open the ZIP file in binary read mode
with open(test_results_zip_path, 'rb') as f:
files = {
'file': f
}
data = {
'projectKey': 'PROJECT_KEY', # Replace with your actual project key
'reportType': 'JUNIT', # The format of the test results
'jobUrl': 'https://ci.example.com/job/123', # URL to the CI job
'testExecutionFields': json.dumps(test_execution_fields), # Convert dict to JSON string
}
try:
# Send a POST request to the RTM API
response = requests.post(url, headers=headers, files=files, data=data)
response.raise_for_status() # Raise an exception for HTTP errors
# Print the import task ID returned by the API
print('Import Task ID:', response.json())
except requests.exceptions.RequestException as e:
print('Request failed:', e)
if response is not None:
print('Response Status Code:', response.status_code)
print('Response Text:', response.text)
except ValueError:
print('Response could not be parsed as JSON:', response.text)
If you can’t find the answer you need in our documentation, raise a support request. Include as much information as possible to help our support team resolve your issue faster.