App page
Requirements and Test Management for Jira
Cloud Server/Data Center
Requirements and Test Management for Jira

Cloud

Server/Data Center

Documentation
FAQ
Release notes
Migration to Cloud
Last updated Dec 27, 2024

Introduction

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.

Example

If you aren’t sure how to create a XML file for the import, download the sample file.

Quick start to Test Automation

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:

  • Speeds up the testing process.
  • Ensures consistency, minimizing errors.
  • Reduces the effort required for execution and validation.

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.

Create API Token

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.

Tip

If you already have an API token then you can use it to import test results and skip this step.

Steps

  1. Go to Apps > Manage your apps.
Navigate to manage apps.
Navigate to manage apps.
  1. Click API Tokens.
API Tokens.
Navigate to API Tokens.
  1. Click Generate Token.
Generate Token.
Generate Token.
  1. Configure the Token:
  • Select user - select the user account under which the API token is generated. This account is associated with all actions performed using the token.
  • Label - enter a descriptive label for the API token to help identify its purpose (for example., Jenkins CI Integration).
  • Select access - select access for automation. This is optional, because by default the token is available to all endpoints. Select automation so that the access token has access only to automation endpoints (for example, import)
  1. Click Generate.
Configure the Token.
Configure the Token.
  • Copy the generated Token.
Warning

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.

Result

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.

Example

Here is the example header:

Authorization: Bearer YOUR_API_TOKEN

Replace YOUR_API_TOKEN with the generated Token.

Locate RTM API base URL

To access the base URL for the RTM API:

  1. Navigate to the Requirements and Test Management app in your project.
  2. Click .
  3. Click REST API authentication.
Navigate to REST API authentication.
Navigate to REST API authentication.
  1. The window on the screen shows:
  • Data Residency: The location of the data.
  • API URL Base: The base URL for the RTM API requests.
  1. Copy the API URL base to use it in the API requests.

Run import

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

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'
Note

See REST API for all available options for import endpoint

Example

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)

Need help?

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.