Get closed defects associated with a failed test run
The following flow demonstrates how to get a list of closed defects that are associated with a failed test run. You might want to call this API to further examine how a defect could be closed if its run failed.
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 fields |
---|---|---|---|
Defect | Phase | The phase indicates the status of an item, such as a defect. | phase |
Run | Defects can be opened when running tests. | ||
Run | Test | Runs are associated with tests. | test |
Defect | Defects can be opened for specific runs, for example, when discovered during that run. | run | |
Tests | Run |
This aggregate resource collection represents types of tests, including manual, Gherkin, test suites, and automated. Tests can be associated with runs. |
run |
Flow
Let's create the REST API call step-by-step.
-
A defect is closed, but a test associated with the defect is still failing. The test in this flow has the ID 1113.
As a first step, we list all defects in workspace 1002.
GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/defects
-
Let's now start building our query_clause. Our query clause will check for three criteria. We will separate each criteria with with a semi-colon (;), which represents the And operator.
The first criteria is to list defects in the workspace that are closed.
We use the phase reference field and filter by the logical_name field in the phase list for defects to look for closed phases only.
GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/defects?query="phase EQ {logical_name EQ ^phase.defect.closed^}"
-
In addition to examining only closed defects, we only want to look at the runs for a specific test, 1113. We use cross-filtering for this.
GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/defects?query="phase EQ {logical_name EQ ^phase.defect.closed^};run EQ {test EQ {id EQ 1113}}"
-
Lastly, we want to add a clause to our query clause which checks the status of the run. We want to see only those defects for the test runs that failed. We use the status reference field and filter by the logical_name field in the list node for failed statuses.
GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/defects?query="phase EQ {logical_name EQ ^phase.defect.closed^};run EQ {test EQ {id EQ 1113}; status EQ {logical_name EQ ^list_node.run_status.failed^}}"
The complete REST API call for this flow is:
GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/defects?query="phase EQ {logical_name EQ ^phase.defect.closed^};run EQ {test EQ {id EQ 1113}; status EQ {logical_name EQ ^list_node.run_status.failed^}}"
Javascript example
/** * Flow: How to find closed defects with associated failing test run. * Use case: I have reported the defect as closed, but the test is still failing. * Find closed defects of all failing runs of a specific test with id x. * @param requestor */
function getClosedDefectsWithFailingTests1(requestor) { var testId = 1113; requestor.get('/defects?query="phase EQ {logical_name EQ ^phase.defect.closed^};' + 'run EQ {test EQ {id EQ '+ testId +'};' + ' status EQ {logical_name EQ ^list_node.run_status.failed^}}"', function(error, message, defects) { console.info(defects); }); } exports.getClosedDefectsWithFailingTests1 = getClosedDefectsWithFailingTests1;
See also: