我正在使用以下代码来获取TestSet ID。但这没有任何结果

QueryRequest testsetRequest = new QueryRequest("Test Set");
testsetRequest.setFetch(new Fetch("FormattedID","Name"));
testsetRequest.setQueryFilter(new QueryFilter("TestSet.Name", "=", "TestSetName"));
QueryResponse testSetQueryResponse = restApi.query(testsetRequest);
System.out.println(String.format("\nTestSet:%d",testSetQueryResponse.getTotalResultCount()));
StringTestSetref=testSetQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").toString();
System.out.println(TestSetref);

最佳答案

您的查询中可能会出现错误。这样的代码应该工作。 else子句还可以帮助您诊断查询出现问题时遇到的错误。

QueryRequest testsetRequest = new QueryRequest("TestSet"); //no spaces
testsetRequest.setFetch(new Fetch("FormattedID","Name"));

//No need to specify type again
testsetRequest.setQueryFilter(new QueryFilter("Name", "=", "TestSetName"));
QueryResponse testSetQueryResponse = restApi.query(testsetRequest);

if(testSetQueryResponse.wasSuccessful()) {
    for (JsonElement result : testSetQueryResponse.getResults()) {
        //handle results
    }
} else {
    //See what error occurred
    for (String err : testSetQueryResponse.getErrors()) {
        System.err.println("\t" + err);
    }
}

关于java - 如何使用Java中的Rally Rest API获取TestSet ID?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12819433/

10-10 10:09