2

当我请求“TestSet”查询以获取特定测试集中的 TestCases 时。但是,获取的 TestCases 包含项目中测试用例的完整列表,而不是特定测试集中的测试用例。

QueryRequest queryTestSet = new QueryRequest("TestSet");

queryTestSet.setFetch(new Fetch("Name", "Project", "TestCases"));
queryTestSet.setQueryFilter(new QueryFilter("name", "=", "TestSet_Name"));

QueryResponse responseTestSet =  RallyRestAPI.getAPI().query(queryTestSet);
JsonArray testcasesJson = responseTestSet.getResults().get(0).getAsJsonObject().getAsJsonArray("TestCases");

例如,项目中总共有500个测试用例我在TestSet中添加了“自动化”测试用例的测试用例和结果(300个测试用例)然后,我请求上面的查询,“testcasesJson”的大小返回500,它包括完整的测试用例列表。

如何阅读仅在 TestSet 中添加的测试用例?

Rally Rest JAR 版本: rally-rest-api-1.0.7.jar

4

1 回答 1

1

这个使用 2.0.4 jar 的代码示例仅返回与测试集关联的测试用例:

public class GetTCofTS {

    public static void main(String[] args) throws Exception {

        String host = "https://rally1.rallydev.com";

        String username = "user@co.com";
        String password = "secret";

        String applicationName = "RESTExampleFindTestCasesOfTestSet";
        String workspaceRef = "/workspace/1111";
        String projectRef = "/project/2222";
        String wsapiVersion = "1.43";


        RallyRestApi restApi = null;
        try {
            restApi = new RallyRestApi(
                    new URI(host),
                    username,
                    password);
            restApi.setApplicationName(applicationName); 

            QueryRequest testSetRequest = new QueryRequest("TestSet");
            testSetRequest.setWorkspace(workspaceRef);
            restApi.setWsapiVersion(wsapiVersion);
            testSetRequest.setFetch(new Fetch(new String[] {"Name", "TestCases", "FormattedID"}));

            testSetRequest.setQueryFilter(new QueryFilter("Name", "=", "someTS"));

            QueryResponse testSetQueryResponse = restApi.query(testSetRequest);
            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"));
                int numberOfTestCases = testSetJsonObject.get("TestCases").getAsJsonArray().size();
                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"));
                     }
                }

            }

        } finally {
            if (restApi != null) {
                restApi.close();
            }
        }
    }
}
于 2013-11-04T20:30:23.617 回答