Get application modules whose tests recently failed
The following flow demonstrates how to get a list of application modules whose automated tests failed 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.
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 | Tests |
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 |
Product Area | Test | Tests can be associated with product areas (also known as application modules). | test |
Flow
Let's create the REST API call step-by-step.
-
We can start by listing all the product areas in the workspace.
GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/product_areas
-
Let's build our query_clause. We are only interested in the product areas that are associated with tests whose runs failed and had run in the last 24 hours.
This is a nested query. We will be querying for certain runs of the tests associated with the product areas in our workspace.
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.
Let's start from the outermost clauses of the query. We will fill in the innermost query soon.
GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/product_areas?query="test EQ {last_runs EQ { inner_query }}"
-
Now that we see how to look for the last runs of a test, 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 is run_status, which is a list_node. We want to compare the last run's status with the run_status list's value failed.
GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/product_areas?query="test EQ {last_runs EQ {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.
-
Now we see application modules in the workspace that are associated with failed runs for automated tests. But we want to see only those application modules 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 15, 2016 at 6:45, we would query for runs after July 14, 2016.
GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/product_areas?query="test EQ {last_runs EQ {status EQ {logical_name EQ ^list_node.run_status.failed^};creation_time GT ^2016-07-14T06:45:48Z^}}"
The complete REST API call for this flow is:
GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/product_areas?query="test EQ {last_runs EQ {status EQ {logical_name EQ ^list_node.run_status.failed^};creation_time GT ^2016-07-14T06:45:48Z^}}"
Javascript example
* Flow: How to find application modules with failed tests (within the last 24 hours) * @param requestor */
function getModulesWithFailingTests(requestor) { requestor.get('/product_areas?query="test EQ {last_runs EQ {status EQ {logical_name EQ ^list_node.run_status.failed^};' + 'creation_time GT ^' + getLast24HoursDateString() + '^}}"', function(error, message, product_areas) { console.info(product_areas); }); } exports.getModulesWithFailingTests = getModulesWithFailingTests;
function getLast24HoursDateString() { var date = new Date(); date.setDate(date.getDate() - 1); return date.toISOString(); }
See also: