Applies to TM4J Server/Data Center 7.0, last modified on July 07, 2020

Automated testing has become an essential part of the testing process, freeing up time for the team and reducing the rate of errors that occur in manual testing. Coding automated tests that run either locally or during builds using continuous-integration (CI) tools gives you a quick and standardized understanding of whether your code is safe to release. This is why we have invested effort to improve our integrations with CI tools such as Jenkins and Bamboo and automated testing in general.

Test Management for Jira offers a range of features that simplify the integration process. We provide a plugin for Jenkins that allows you to both pull BDD test cases from Jira and report the results back to Jira. Our full-featured REST API can be used for a more custom approach to this. We currently support Cucumber and JUnit tests.

Using these features and functionalities removes the need to create custom scripts to post data to Test Management for Jira and makes the process much more simple. The sections below offer workflow examples for the development project, CI server, and Test Management for Jira.

REST API endpoints

Whichever tool you use for automated testing, we have a public REST API with an extensive set of endpoints that can be used to create custom scripts and enable full integration.

The following image demonstrates the flow of actions from your CI tool, which outputs the results from automated tests as part of a build. Data is pulled from a results file, manipulated if necessary, and then pushed to Test Management for Jira.

REST API and test automation

Click the image to enlarge it.

With results published back to Test Management for Jira using our REST API, you can view all your testing data in one place.

Sample script: create a test cycle with test executions

The script below provides an example of how to create a test cycle (and then test executions as part of this cycle) in Test Management for Jira, using the REST API.

JavaScript / Node.js

// Create a test cycle with test executions.
// The test execution results could have come from an automated test tool, for example.

const fetch = require('node-fetch');

class TestExecutionCreator {
    constructor(jiraSettings, executionResults, projectKey) {
      this._jiraSettings = jiraSettings;
      this._executionResults = executionResults;
      this._projectKey = projectKey;
      this._authString = 'Basic ' + Buffer.from(this._jiraSettings.user + ':' + this._jiraSettings.password).toString('base64');
}

    async createExecutions() {
        const request = this._buildRequest({
            name: 'Automated test executions',
            projectKey: this._projectKey,
            items: this._executionResults
        });
        const url = encodeURI(this._jiraSettings.url + '/rest/atm/1.0/testrun');
        const response = await fetch(url, request); +
        if(response.status !== 201) throw 'Error creating test cycle.';
        const jsonResponse = await response.json(); +
        console.log('Test cycle created:' + jsonResponse.key);
    }

    _buildRequest(body) {
        return {
            method: 'POST',
            body: JSON.stringify(body),
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
                'Authorization': this._authString
            }
        };
    }
}

async function run() {
// Your settings
const settings = {
  'url': '<<your-jira-url>>',
  'user': '<<your-user>>',
  'password': '<<your-password>>'
};
const projectKey = '<<A project key e.g. PROJ>>';

    // These test results could have been generated by an automated test tool
    const executionResults = [{
            'testCaseKey': '<<A test case key>>',
            'status': 'Pass',
            'environment': 'Firefox',
            'executionTime': 180000,
            'executionDate': '2018-12-13T15:22:00-0300',
        }, {
            'testCaseKey': '<<A test case key>>',
            'status': 'Fail',
            'environment': 'Chrome',
            'executionTime': 365000,
            'executionDate': '2018-12-13T18:11:00-0300',
        }, {
            'testCaseKey': '<<A test case key>>',
            'status': 'Pass'
        }, {
            'testCaseKey': '<<A test case key>>',
            'status': 'Fail'
        }];

    await new TestExecutionCreator(settings, executionResults, projectKey).createExecutions();
}

run();

See Also

Test Automation and API

Highlight search results