Get recent failed automated tests for a release

The following flow demonstrates how to get a list of failed automated tests for a specific release that were reported in the last 24 hours.

Entity relationship diagram

We need to access the following entities for this flow, and understand the relationships between these entities.

Entity Relationships in this flow Description of relationship Reference / relationship fields
Tests   This aggregate resource collection represents types of tests, including manual, Gherkin, test suites, and automated. subtype
Automated Test Test

The automated test is a subtype of tests.

There is no field that relates back to the aggregate resource collection, tests.

 
Runs

Each automated test can have 0 or more runs associated with it.

We will use the automated test's reference field last_runs to find the last run that occurred in the past 24 hours.

last_runs
Runs Automated test Each run is associated with one test. test_of_last_run
Release Runs must be associated with a release. release
Release Run Releases can be associated with runs. run

Back to top

Flow

Let's create the REST API call step-by-step.

  1. We build a query on the latest runs of the automated tests using the last_runs reference field.

    GET .../api/shared_spaces/<shared space ID>/workspaces/<workspace id>/automated_tests?query="last_runs EQ { <query_clause> }"

  2. Let's now start building our query_clause.

    This query has three sets of criteria: The last runs, the status, and the creation time. We will separate each set with a semi-colon (;), which represents the And operator.

    In this step, we are only interested in the runs that are associated with a specific release, 236.2. We use the name field to specify the release.

    GET .../api/shared_spaces/<shared space ID>/workspaces/<workspace id>/automated_tests?query="last_runs EQ {(release EQ {name EQ ^236.2^})}"

  3. We want to access only those runs with a failed status. This is an example of how to work with list nodes. One of the available lists in ALM Octane is run_status, and we want to compare the last run's status with the run_status list's value failed.

    GET .../api/shared_spaces/<shared space ID>/workspaces/<workspace id>/automated_tests?query="last_runs EQ {(release EQ {name EQ ^236.2^});status EQ {logical_name EQ ^list_node.run_status.failed^}}"

    For details on working with reference fields and list nodes, see Get the allowed values for entity fields.

  4. We only want runs within the last 24 hours, so we check the creation time of the run. Assuming today is December 13th, we can use the following date specification.

    GET /api/shared_spaces/<shared space ID>/workspaces/<workspace id>/automated_tests?query="last_runs EQ {(release EQ {name EQ ^236.2^});status EQ {logical_name EQ ^list_node.run_status.failed^};creation_time GT ^2016-07-12T06:45:48Z^}"

The complete REST API call for this flow is: 

GET .../api/shared_spaces/<shared space ID>/workspaces/<workspace id>/automated_tests?query="last_runs EQ {(release EQ {name EQ ^236.2^});status EQ {logical_name EQ ^list_node.run_status.failed^};creation_time GT ^2016-07-12T06:45:48Z^}"

Back to top

Javascript example

/**
 * Flow: All failing tests in a release reported within last 24h
 * @param requestor
 */
function getFailedTests(requestor) {
  // change for correct release name
  var releaseName = '236.2';
	var automatedTestsEntityName = 'automated_tests';
	//var automatedTestsEntityName = 'test_automateds';

  requestor.get('/'+ automatedTestsEntityName +'?query="last_runs  EQ {(release EQ {name EQ ^' + releaseName + '^});' +
    'status EQ {logical_name EQ ^list_node.run_status.failed^};' +
    'creation_time GT ^' + getLast24HoursDateString() + '^}"', function(error, message, last_runs) {
    console.info(last_runs);
  });
}
exports.getFailedTests = getFailedTests;
function getLast24HoursDateString() {
  var date = new Date();
  date.setDate(date.getDate() - 1);

  return date.toISOString();
}

Back to top

See also: