问题
I have created a test run during the execution time, and I would like to add test cases meanwhile they are starting the execution. The test cases have been created, if they already doesn't exist. And this test case should be added to an existing test run with other test cases.
I have tried to use the setCaseIds
over the run and after update the run, but that override the existing run. I think the error is because I'm using the setCaseIds
, but I don't know the proper way to do.
Case mycase = new Case().setTitle("TEST TITLE").setSuiteId(suite.getId()).setSectionId(section.getId());
mycase = testRail.cases().add(mycase.getSectionId(), mycase, customCaseFields).execute();
final List<Integer> caseToAdd = new ArrayList();
caseToAdd.add(mycase.getId());
run.setCaseIds(caseToAdd);
run = testRail.runs().update(run).execute();
//The first test start the execution
.
.
.
// The first test case finish
// Now I create a new testcase to add
Case mySecondCase = new Case().setTitle("TEST TITLE").setSuiteId(suite.getId()).setSectionId(section.getId());
mycase = testRail.cases().add(mySecondCase.getSectionId(), mySecondCase, customCaseFields).execute();
// I repeat the prevous steps to add a new test case
final List<Integer> newCaseToAdd = new ArrayList();
newCaseToAdd.add(mySecondCase.getId());
run.setCaseIds(newCaseToAdd);
run = testRail.runs().update(run).execute();
Anyone knows how to do that? Thank you in advance.
回答1:
Here is what I was able to find:
- TestRail does not support an add/append operation. It only supports set/override operation. That is what happens in your case when you call setCaseIds two times on the same run it saves the last id only (and that is what you can typically expect from a
set
method). - Suggested solution is:
Run activeRun = testRail.runs().get(1234).execute();
List<Integer> testCaseIds = activeRun.getCaseIds() == null ? new ArrayList<>() : new ArrayList<>(activeRun.getCaseIds());
testCaseIds.add(333);
testRail.runs.update(activeRun.setCaseIds(testCaseIds)).execute();
So instead of just setting a new id(s) you take the existing ids from run, add id(s) to it and update run.
source: https://github.com/codepine/testrail-api-java-client/issues/24
回答2:
I solved the problem with the Plan and Entry structure. I'm saving all the test cases in a list, and this list is passed as parameter in the entry.setCaseIds
function:
// First Test Case
Case mycase = new Case().setTitle("TEST TITLE").setSuiteId(suite.getId()).setSectionId(section.getId());
mycase = testRail.cases().add(mycase.getSectionId(), mycase, customCaseFields).execute();
// List for Test Cases
List<Integer> caseList = new ArrayList<>();
caseList.add(mycase.getId());
// Create new Entry and add the test cases
Entry entry = new Entry().setIncludeAll(false).setSuiteId(suite.getId()).setCaseIds(caseList);
entry = testRail.plans().addEntry(testPlan.getId(),entry).execute();
// Create the second test case
Case mycase2 = new Case().setTitle("TEST TITLE 2").setSuiteId(suite.getId()).setSectionId(section.getId());
mycase2 = testRail.cases().add(mycase.getSectionId(), mycase, customCaseFields).execute();
// Add the second test case to the list
caseList.add(mycase2.getId());
// Set in the Entry all the test cases and update the Entry
entry.setCaseIds(caseList);
testRail.plans().updateEntry(testPlan.getId(), entry).execute();
To execute the test cases you need the test run:
run = entry.getRuns().get(0);
来源:https://stackoverflow.com/questions/52819170/how-to-add-test-cases-to-an-existing-test-run-with-the-api-from-java-to-testrail