如何使用RallyAPI获取测试用例的结果



我是Rally API的新手。我被分配了使用 Rally API 在 java 中获取测试用例结果的任务。有人可以帮我一个示例程序吗?另外,请告诉我如何在集会中获取工作区名称。

下面是一个基于 Rally API Toolkit for Java 的代码示例。另请参阅 WS API 文档,了解 TestCase 和 TestCaseResult 对象的详细信息。

public class GetTestCaseResults {
    public static void main(String[] args) throws Exception {
        String host = "https://rally1.rallydev.com";
        String applicationName = "Example: get Results of TestCase";
        String projectRef = "/project/12345"; //user your own project OID
        String apiKey = "_abc123";
        RallyRestApi restApi = null;
        try {
            restApi = new RallyRestApi(new URI(host),apiKey);
            restApi.setApplicationName(applicationName);
            QueryRequest testCaseRequest = new QueryRequest("TestCase");
            testCaseRequest.setProject(projectRef);
            testCaseRequest.setFetch(new Fetch(new String[] {"FormattedID","Results","LastVerdict"}));
            testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TC3"));
            //testCaseRequest.setLimit(25000);
            testCaseRequest.setScopedDown(false);
            testCaseRequest.setScopedUp(false);
            QueryResponse testCaseResponse = restApi.query(testCaseRequest);
            System.out.println("Successful: " + testCaseResponse.wasSuccessful());
            System.out.println("Size: " + testCaseResponse.getTotalResultCount());
            int totalResults = 0;
            for (int i=0; i<testCaseResponse.getResults().size();i++){
                JsonObject testCaseJsonObject = testCaseResponse.getResults().get(i).getAsJsonObject();
                System.out.println("Name: " + testCaseJsonObject.get("Name") + " FormattedID: " + testCaseJsonObject.get("FormattedID") + " LastVerdict: " + testCaseJsonObject.get("LastVerdict"));
                int numberOfResults = testCaseJsonObject.getAsJsonObject("Results").get("Count").getAsInt();
                if(numberOfResults > 0) {
                    totalResults += numberOfResults;
                    QueryRequest resultsRequest = new QueryRequest(testCaseJsonObject.getAsJsonObject("Results"));
                    resultsRequest.setFetch(new Fetch("Verdict","Date"));
                    //load the collection
                    JsonArray results = restApi.query(resultsRequest).getResults();
                    for (int j=0;j<numberOfResults;j++){
                        System.out.println("Name: " + results.get(j).getAsJsonObject().get("Verdict") + results.get(j).getAsJsonObject().get("Date").getAsString());
                    }
                }
            }
            System.out.println("Total number of results: " + totalResults);
        } finally {
            if (restApi != null) {
                restApi.close();
            }
        }
    }
}

相关内容

最新更新