gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 11:26:31 24 4
gpt4 key购买 nike

当我请求“TestSet”查询以获取特定测试集中的测试用例时。但是,获取的 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

最佳答案

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

关于java - Query TestSet Json 在 Rally Rest API 中返回错误的测试用例列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19774986/

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