Get open defects associated with a successful test run

The following flow demonstrates how to get a list of open defects that are associated with a successful test run.

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
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.


Back to top


You might want to run this API to check for defects that should be closed, based on successful test runs.

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

  1. A defect is open, but the test associated with the defect runs successfully. Perhaps we just forgot to close the defects. 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

  2. Let's now start building our query_clause. Our query clause will check for three criteria. We separate the criteria with semi-colons (;), which represents the And operator.

    The first criteria is to list defects in the workspace that are fixed. We use the phase reference field and filter by the logical_name field in the phase list for defects to look for fixed phases only.

    GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/defects?query="phase EQ {logical_name EQ ^phase.defect.fixed^}"

  3. In addition to examining only fixed defects, we only want to look at the runs for a specific test, 1113.

    GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/defects?query="phase EQ {logical_name EQ ^phase.defect.fixed^};run EQ {test EQ {id EQ 1113};}"

  4. 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 were successful (passed).

    Status is a reference field. We use the logical_name field on the list node for run statuses to check for a status of passed.

    GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/defects?query="phase EQ {logical_name EQ ^phase.defect.fixed^};run EQ {test EQ {id EQ 1113}; status EQ {logical_name EQ ^list_node.run_status.passed^}}"

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.fixed^};run EQ {test EQ {id EQ 1113}; status EQ {logical_name EQ ^list_node.run_status.passed^}}"

Back to top

Javascript example

 * Flow: How to find open defects with associated successful run.
 * Use case:  I have fixed the defect and the test is find but I forgot to close the defect.
 * Find fixed defects with all associated successful run of a test with id x
 * @param requestor
function getClosedDefectsWithFailingTests2(requestor) {
  var testId = 1113;

  requestor.get('/defects?query="phase EQ {logical_name EQ ^phase.defect.fixed^};' +
    'run EQ {test EQ {id EQ '+ testId +'};' +
    ' status EQ {logical_name EQ ^list_node.run_status.passed^}}"', function(error, message, defects) {;

exports.getClosedDefectsWithFailingTests2 = getClosedDefectsWithFailingTests2;

Back to top

See also: