gpt4 book ai didi

java - 如何检索与测试集关联的测试用例

转载 作者:行者123 更新时间:2023-11-29 08:56:48 25 4
gpt4 key购买 nike

我尝试为 jar 2.0.2 运行提供的代码,现在为 2.0.4 运行,两次都在以下行收到错误:int numberOfTestCases = testSetJsonObject。 get("TestCases").getAsJsonArray().size();

Exception in thread "main" java.lang.IllegalStateException: This is not a JSON Array. at com.google.gson.JsonElement.getAsJsonArray(JsonElement.java:106) at GetTCofTS.main(GetTCofTS.java:50)

我可以克服这个错误(因为它实际上不是返回的数组),但它不会解决我的问题,我不仅要获取与当前 TestSet 关联的 TestCases 的数量,而且测试用例列表——至少是它们的格式化 ID。它是拉力赛中的包吗?

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();
}
}
}
}

最佳答案

v2.0 是 future 的首选版本。以下小调整应该可以让您开始行动。

而不是这个(在 1.43 中有效,因为返回了集合):

int numberOfTestCases = testSetJsonObject.get("TestCases").getAsJsonArray().size();
if(numberOfTestCases>0) {
for (int j=0;j<numberOfTestCases;j++) {
System.out.println(testSetJsonObject.get("TestCases").getAsJsonArray().get(j).getAsJsonObject().get("FormattedID"));
}
}

这样做:

//TestCases is an object with a Count and a ref to load the collection
int numberOfTestCases = testSetJsonObject.getAsJsonObject("TestCases").get("Count").getAsInt();

if(numberOfTestCases > 0) {
QueryRequest testCaseRequest = new QueryRequest(testSetJsonObject.getAsJsonObject("TestCases"));
testCaseRequest.setFetch(new Fetch("FormattedID"));
//load the collection
JsonArray testCases = restApi.query(testCaseRequest).getResults();
for (int j=0;j<numberOfTestCases;j++){
System.out.println(testCases.get(j).getAsJsonObject().get("FormattedID").getAsString());
}
}

关于java - 如何检索与测试集关联的测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19934895/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com