Share this page

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

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
--- | --- | --- | ---
Defect | Phase | The phase indicates the status of an item, such as a defect. | phase
Defect | Run | Defects can be opened when running tests. | None
Run | Test | Runs are associated with tests. | test
Run | 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

Back to top

## Flow

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) {
        console.info(defects);
      });
    }

    exports.getClosedDefectsWithFailingTests2 = getClosedDefectsWithFailingTests2;

Back to top

See also:

- REST API calls
- Common flows and ER diagrams
- Get closed defects associated with a failed test run

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: