Query TestSet Json在Rally Rest API中返回错误的测试用例列表

时间:2013-11-04 18:57:15

标签: java rally

当我请求“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

1 个答案:

答案 0 :(得分: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();
            }
        }
    }
}