我的想法是更新测试集中出现的测试用例结果。但是我无法在测试集中显示测试用例。 我想进入测试集并获得测试用例,我可以查询每个测试
RallyRestApi restApi = new RallyRestApi(new URI(“https://rally1.rallydev.com”),“username”,“pass”); restApi.setApplicationName( “CrudExample”);
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").getAsJsonArray().size();
GetRequest getRequest = new GetRequest("https://rally1.rallydev.com/slm/webservice/v2.0/TestSet/15150807/TestCases");
GetResponse getResponse = restApi.get(getRequest);
JsonObject obj = getResponse.getObject();
System.out.println(obj.getAsString());
int numberOfTestCases = testSetJsonObject.get("TestCases").getAsJsonObject().get("Count").getAsInt();
System.out.println(numberOfTestCases);
if(numberOfTestCases>0){
for (int j=0;j<numberOfTestCases;j++){
System.out.println(testSetJsonObject.get("TestCases").getAsJsonArray().get(j).getAsJsonObject().get("FormattedID"));
}
}
}
}
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]);
}
}
输出:
成功:是的 尺寸:1 名称:“预验收自动回归”ref:rally1.rallydev.com/slm/webservice/v2.0/testset/15150807667 测试案例:“rally1.rallydev.com/slm/webservice/v2.0/TestSet/15150807667/TestCases
答案 0 :(得分:0)
而不是:
int numberOfTestCases = testSetJsonObject.get("TestCases").getAsJsonObject().get("Count").getAsInt();
System.out.println(numberOfTestCases);
if(numberOfTestCases>0){
for (int j=0;j<numberOfTestCases;j++){
System.out.println(testSetJsonObject.get("TestCases").getAsJsonArray().get(j).getAsJsonObject().get("FormattedID"));
}
使用此:
if(numberOfTestCases>0){
QueryRequest testCaseRequest = new QueryRequest(testSetJsonObject.getAsJsonObject("TestCases"));
testCaseRequest.setFetch(new Fetch(new String[] {"Name", "Results", "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());
}
}