Share this page

# Get features whose automated tests recently failed

The following flow demonstrates how to get a list of features whose associated automated test runs failed in the last 24 hours.

In this topic:

## Entity relationship diagram

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

The following shows the relations in the flow.

Entity | Relationships in this flow | Description of relationship | Reference / relationship fields
--- | --- | --- | ---
Tests | None | 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. | None
Automated Test | 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
Runs | List | Each run has a status, and the statuses are stored in a list node. | status
Feature | Automated Test | Automated (and manual) tests can be associated with features. | test
Feature | Theme | Each feature must be assigned to a theme. The feature is considered a child of the theme. | children
Feature | Story | Each feature can have 0 or more stories. The stories (user stories and defects) are considered children of the feature. | children

Back to top

## Flow

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

1. We can start by listing all the features in the workspace.

   `GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/features`

2. Let's build our query_clause. We are only interested in the features that are associated with tests whose runs failed and had run in the last 24 hours.

   This query has two sets of criteria. We want to list any failed tests that are related to the feature directly, and any failed tests that are related to the feature's children. We will use the || to indicate the OR condition, so that any run that matches both cases is listed.

   Additionally, this is a nested query. We will be querying for certain runs of the tests associated with the features in our workspace.

   Let's start from the outermost clauses of the query clause that checks for the runs of tests related to the feature's children. We will fill in the <inner_query> soon.

   This part of the query clause shows that we are looking for the user stories and defects (children) of the feature that have tests whose last runs match the inner_query clause.

   `GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/features?query="children EQ {test EQ {<inner_query>}}"`

3. Now that we see how to look for the last runs of tests related to our features' children, we can specify which last runs we want to get by filling in the inner query. 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 for automated tests is run_status, which is a list_node. We want to compare the last automated run's status with the run_status list's value failed.

   `GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/features?query="children EQ {test EQ {last_runs EQ {status EQ {logical_name EQ ^list_node.run_status.failed^}"`

4. Now we see features in the workspace that are associated with failed runs for automated tests. But we want to see only those features associated with failed runs created in the last 24 hours.

   This is an example of how to work with creation time fields. Note the format of the date. Assuming today is July 20, 2016 at 6:45, we would query for runs after July 18, 2016.

   `GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/features?query="children EQ {test EQ {last_runs EQ {status EQ {logical_name EQ ^list_node.run_status.failed^};creation_time GT ^2016-07-18T06:45:48Z^}}}"`

5. Now we have exactly what we need to list the features whose children's test runs failed. We can add the || operator to add the second part of our query, which looks for features whose test runs failed (not the children's):

   `GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/features?query="children EQ {test EQ {last_runs EQ {status EQ {logical_name EQ ^list_node.run_status.failed^};creation_time GT ^2016-07-18T06:45:48Z^}}}||test EQ {last_runs EQ {status EQ {logical_name EQ ^list_node.run_status.failed^};creation_time GT ^2016-07-18T06:45:48Z^}}"`

The complete REST API call for this flow is:

`GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/features?query="children EQ {test EQ {last_runs EQ {status EQ {logical_name EQ ^list_node.run_status.failed^};creation_time GT ^2016-07-18T06:45:48Z^}}}||test EQ {last_runs EQ {status EQ {logical_name EQ ^list_node.run_status.failed^};creation_time GT ^2016-07-18T06:45:48Z^}}"`

Back to top

## Javascript example

    /**
     * Flow:  How to find features in this release with failing tests (within the last 24 hours)
     * @param requestor
     */
    function getFeaturesInReleaseWithFailingTests(requestor) {
      var last24HoursDateString = getLast24HoursDateString();

      requestor.get('/features?query="children EQ {test EQ {last_runs EQ {status  EQ {logical_name EQ ^list_node.run_status.failed^};' +
        'creation_time GT ^' + last24HoursDateString + '^}}}' +
        '||' +
        'test EQ {last_runs EQ {status  EQ {logical_name EQ ^list_node.run_status.failed^};' +
        'creation_time GT ^' + last24HoursDateString + '^}}"', function(error, message, features) {
        console.info(features);
      });
    }

    exports.getFeaturesInReleaseWithFailingTests = getFeaturesInReleaseWithFailingTests;

    function getLast24HoursDateString() {
      var date = new Date();
      date.setDate(date.getDate() - 1);

      return date.toISOString();
    }

Back to top

See also:

- REST API calls
- Common flows and ER diagrams

https://admhelp.microfocus.com Software Delivery Management 8942
Tips to improve your search results... OpenText™ Software Delivery Management Help Center OpenText™ Software Delivery Management Help 26.1 All View Local Help Center View Online Help Center Version: