虽然我能够提取特定测试集中的所有测试用例并修改或更新所有测试结果。 更新测试集中的测试用例后,测试集未反映判定(通过/失败)。
如果我导航到其中一个测试用例详细信息页面,我可以看到更新的测试用例结果
这是更新测试用例后的测试设置状态
但是当其中一个测试用例打开时,我能够看到更新的测试用例结果
代码: QueryRequest testSetRequest = new QueryRequest(“TestSet”); testSetRequest.setFetch(new Fetch(new String [] {“Name”,“TestCases”,“FormattedID”}));
testSetRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TS346"));
QueryResponse testSetQueryResponse = restApi.query(testSetRequest);
if(testSetQueryResponse.wasSuccessful()){
System.out.println("Successful: " + testSetQueryResponse.wasSuccessful());
System.out.println("Size: " + testSetQueryResponse.getTotalResultCount());
for (int i=0; i<testSetQueryResponse.getResults().size();i++){
JsonObject testSetJsonObject = testSetQueryResponse.getResults().get(i).getAsJsonObject();
System.out.println("Name: " + testSetJsonObject.get("Name") + " ref: " + testSetJsonObject.get("_ref").getAsString() + " Test Cases: " + testSetJsonObject.get("TestCases").getAsJsonObject().get("_ref"));
int numberOfTestCases = testSetJsonObject.get("TestCases").getAsJsonObject().get("Count").getAsInt();
System.out.println(numberOfTestCases);
if(numberOfTestCases>0){
QueryRequest testCaseRequest = new QueryRequest(testSetJsonObject.getAsJsonObject("TestCases"));
testCaseRequest.setFetch(new Fetch("FormattedID"));
//load the collection
JsonArray testCases = restApi.query(testCaseRequest).getResults();
for (int j=0;j<numberOfTestCases;j++){
System.out.println(testCases.get(j).getAsJsonObject().get("FormattedID").getAsString());
String s= testCases.get(j).getAsJsonObject().get("FormattedID").getAsString();
testCaseRequest = new QueryRequest("TestCase");
testCaseRequest.setFetch(new Fetch("FormattedID","Name"));
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", s));
QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);
String testCaseRef = testCaseQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").getAsString();
try{
//Add a Test Case Result
System.out.println("Creating Test Case Result...");
JsonObject newTestCaseResult = new JsonObject();
newTestCaseResult.addProperty("Verdict", "Pass");
newTestCaseResult.addProperty("Date", "2013-11-29T18:00:00.000Z");
newTestCaseResult.addProperty("Notes", "Automated Selenium Test Runs");
newTestCaseResult.addProperty("Build", "208");
newTestCaseResult.addProperty("TestCase", testCaseRef);
CreateRequest createRequest = new CreateRequest("testcaseresult", newTestCaseResult);
CreateResponse createResponse = restApi.create(createRequest);
if(createResponse.wasSuccessful()){
System.out.println(String.format("Created %s", createResponse.getObject().get("_ref").getAsString()));
//Read Test Case
String ref = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
System.out.println(String.format("\nReading Test Case Result %s...", ref));
GetRequest getRequest = new GetRequest(ref);
getRequest.setFetch(new Fetch("Date", "Verdict"));
GetResponse getResponse = restApi.get(getRequest);
JsonObject obj = getResponse.getObject();
System.out.println(String.format("Read Test Case Result. Date = %s, Verdict = %s", obj.get("Date").getAsString(), obj.get("Verdict").getAsString()));
} else {
String[] createErrors;
createErrors = createResponse.getErrors();
System.out.println("Error occurred creating Test Case: ");
for ( i=0; i<createErrors.length;i++) {
System.out.println(createErrors[i]);
}
}
}
finally{
}
}
}
}
}
else {
String[] createErrors;
createErrors = testSetQueryResponse.getErrors();
System.out.println("Error occurred creating Test Case: ");
for (int i=0; i<createErrors.length;i++) {
System.out.println(createErrors[i]);
}
}
所以,不知道如何更新测试集结果
答案 0 :(得分:0)
只需在新的测试用例结果中添加以下代码
newTestCaseResult.addProperty(“TestSet”,testsetref);