在Rally中如何获取测试集中测试用例的执行状态

时间:2013-11-20 07:17:22

标签: java rally

我想使用Rally Java API获取测试集中测试用例的执行状态。 以下代码段返回测试用例的上次执行状态。但我希望该测试用例的执行状态在特定的测试集中。

    QueryRequest testSetRequest = new QueryRequest("TestSet");

    testSetRequest.setFetch(new Fetch(new String[] { "Name", "TestCases",
            "FormattedID", "LastVerdict","LastRun" }));

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

    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++)
            {
                JsonObject tcObj = testSetJsonObject.get("TestCases")
                        .getAsJsonArray().get(j).getAsJsonObject();
                System.out.println(tcObj.get("FormattedID")+"----"+tcObj.get("LastVerdict"));
            }
        }
    }

1 个答案:

答案 0 :(得分:3)

    QueryRequest testCaseResultsRequest = new QueryRequest("TestCaseResult");
    testCaseResultsRequest.setFetch(new Fetch("Build","TestCase","TestSet", "Verdict","FormattedID"));
    testCaseResultsRequest.setQueryFilter(new QueryFilter("TestCase.FormattedID", "=", "TC8147").and(
            new QueryFilter("TestSet.FormattedID", "=", "TS363")));
    QueryResponse testCaseResultResponse = restApi.query(testCaseResultsRequest);
    int numberTestCaseResults = testCaseResultResponse.getTotalResultCount();
    System.out.println(numberTestCaseResults);
    if(numberTestCaseResults >0)
        System.out.println(testCaseResultResponse.getResults().get(0).getAsJsonObject().get("Verdict").getAsString());
    else
        System.out.println("Not executed");