如何获得特定测试用例的Rally测试用例步骤参考

时间:2014-03-13 11:22:18

标签: rally

我需要更新特定TestCase ex的测试步骤: TC1020

我有以下代码,它返回TestCaseResopnse

        QueryRequest testStepRequest = new QueryRequest("TestCase");
        testStepRequest.setFetch(new Fetch("TC2006", "Name", "Steps")); //
        testStepRequest.setQueryFilter(new QueryFilter("FormattedID", "=",
                "TC2006"));
        QueryResponse qresponse = restApi.query(testStepRequest);

输出

{   " QueryResult":{     " _rallyAPIMajor":" 2",     " _rallyAPIMinor":" 0",     "错误":[

],
"Warnings": [
  "It is no longer necessary to append \".js\" to WSAPI resources."
],
"TotalResultCount": 1,
"StartIndex": 1,
"PageSize": 200,
"Results": [
  {
    "_rallyAPIMajor": "2",
    "_rallyAPIMinor": "0",
    "_ref": "https://us1.rallydev.com/slm/webservice/v2.0/testcase/17577048802",
    "_refObjectUUID": "cd9b3b44-9f56-40fc-a486-3149479786a9",
    "_objectVersion": "6",
    "_refObjectName": "Emp_DataCorrectness_AllUnmatched",
    "Name": "Emp_DataCorrectness_AllUnmatched",
    "Steps": {
      "_rallyAPIMajor": "2",
      "_rallyAPIMinor": "0",
      "_ref": "https://us1.rallydev.com/slm/webservice/v2.0/TestCase/17577048802/Steps",
      "_type": "TestCaseStep",
      "Count": 5
    },
    "_type": "TestCase"
  }
]

} }

我能够将Count计为5,这是预期的。现在我想获得所有测试步骤的TestCaseStep参考(例如:https://us1.rallydev.com/slm/webservice/v2.0/testcasestep/17577048860) 当我复制URL浏览器时,我能够在JSON响应中看到全部5个TestStepReference。现在我想从RestAPI实现它。

任何帮助都是高度赞赏的

此致 基兰

1 个答案:

答案 0 :(得分:0)

在WSAPI 2.0中,由于性能原因,不再返回对象的子集合,因此有必要进行后续查询以获取它们。因此,您需要执行以下操作:

JsonArray myTestCases = qresponse.getResults();

for (int i=0; i<myTestCases.size(); i++) {
    JsonObject testCase = myTestCases.get(i).getAsJsonObject();
    QueryRequest testStepRequest = new QueryRequest(testCase.getAsJsonObject("Steps"));
    testStepRequest.setFetch(new Fetch("StepIndex", "Input", "ExpectedResult"));
    JsonArray testCaseSteps = restApi.query(testStepRequest).getResults();
    for (int j=0;j<testCaseSteps.size();j++){                       
        System.out.println(
            testCaseSteps.get(j).getAsJsonObject().get("StepIndex").getAsString() + ": " + 
            testCaseSteps.get(j).getAsJsonObject().get("Input").getAsString() + ":" + testCaseSteps.get(j).getAsJsonObject().get("ExpectedResult").getAsString());
    }
}

在这个答案中有一个更彻底的解释:

Migrating from Rally API 1.43 to 2.0 - Object Model

如果示例用于从TestSet获取TestCase集合,则该过程完全类似。