如何将测试用例添加到使用API​​从Java到TestRail的现有测试运行中?

如何将测试用例添加到使用API​​从Java到TestRail的现有测试运行中?

问题描述:

我在执行期间创建了一个测试运行,我想在它们开始执行的同时添加测试用例.测试用例已经创建(如果尚不存在).并且此测试用例应与其他测试用例一起添加到现有测试运行中.

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.

我已尝试在运行过程中以及在更新运行过程后使用setCaseIds,但这会覆盖现有的运行过程.我认为错误是因为我正在使用setCaseIds,但我不知道正确的处理方法.

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.

我解决了计划和录入结构的问题.我将所有测试用例保存在一个列表中,并且此列表作为entry.setCaseIds函数中的参数传递:

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);