Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.

How to ADD test cases to test Plan Run with api update_plan_entry


I have read every forum thread I could find on using update_plan_entry and could not find a straight answer on how to add test Cases to an existing Run in a Plan.

Too often Gurock seemed to beat around the bush and not clearly state that passing case_id list to update_plan_entry REPLACES the tests in the Run.

Or they often gave the advice of adding all the test cases from an automation run upfront so as to save on API calls.

First, quite often on a non-trivial automation system the exact test cases that will be run is determined during the run. Second, what does it matter the number of API calls? A computer is doing them.

The solution is simple, but from the API documentation it is not clear that it would work, including maintaining Result status of the existing Tests in the run:

  1. Add Plan
  2. Add Run with initial set of Cases (API will not allow an empty Run) and include_all=False (it is True by default)
  3. Add Results to any Tests in Run as needed
  4. Get list of existing Tests in Run
  5. From list create list of Case IDs - not Test IDs
  6. Append to list Case IDs to add to Run
  7. Call update_plan_entry with case_ids={list of all Case IDs: existing and new}

I have tested this works and Tests with Results already in the Run will still have the same Result status as before the update. (Which seems a bit like behind-the-scene magic since update_plan_entry takes Case IDs and not Test IDs. I suspect the API sees a given Case ID already exists in Run and does not replace it.)

Here is python code snippet that does steps 4-7 above.

Note the behavior is triggered by passing in the Run ID (a value update_plan_entry does not use):

def update_plan_entry(self, plan_id, entry_id, name=None, 
        case_ids=None, run_id=None, include_all=None, 
        description=None, assignedto_id=None):
    uri = 'update_plan_entry/{}/{}'.format(plan_id, entry_id)
    data = {}
    if name is not None:
        data['name'] = name
    ... (other stmts to add updates to data{})
    if case_ids is not None:
        data['case_ids'] = list(case_ids)
        if run_id is not None:
            # special behavior:
            # perform update by adding case_ids to existing 
            # ones in the given run of this entry.
            existing_tests = self.get_tests(run_id)
            for t in existing_tests:
    return self.send_post(uri, data)