Java 如何检索与测试集关联的测试用例
我试图为Java 如何检索与测试集关联的测试用例,java,rally,Java,Rally,我试图为jar2.0.2运行提供的代码,现在为2.0.4运行提供的代码时,两次都在第行收到一个错误:int numberOfTestCases=testSetJsonObject.get(“TestCases”).getAsJsonArray().size() 我可以克服这个错误(因为它实际上不是一个返回的数组),但它不能解决我的问题,我不仅试图获取与当前测试集相关联的测试用例的数量,而且还要获取测试用例的列表-至少是它们的格式化ID。它是一个包吗 public class GetTCofTS
jar2.0.2
运行提供的代码,现在为2.0.4
运行提供的代码时,两次都在第行收到一个错误:int numberOfTestCases=testSetJsonObject.get(“TestCases”).getAsJsonArray().size()代码>
我可以克服这个错误(因为它实际上不是一个返回的数组),但它不能解决我的问题,我不仅试图获取与当前测试集相关联的测试用例的数量,而且还要获取测试用例的列表-至少是它们的格式化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();
}
}
}
}
公共类GetTCofTS{
公共静态void main(字符串[]args)引发异常{
字符串主机=”https://rally1.rallydev.com";
字符串用户名=”user@co.com";
字符串password=“secret”;
字符串applicationName=“restexamplefindtestcasesofestset”;
字符串workspaceRef=“/workspace/1111”;
字符串projectRef=“/project/2222”;
字符串wsapiVersion=“1.43”;
RallyRestApi restApi=null;
试一试{
restApi=新的RallyRestApi(
新URI(主机),
用户名,
密码);
restApi.setApplicationName(applicationName);
QueryRequest testSetRequest=新的QueryRequest(“测试集”);
testSetRequest.setWorkspace(workspaceRef);
restApi.setWsapiVersion(wsapiVersion);
setFetch(新的Fetch(新字符串[]{“Name”,“TestCases”,“FormattedID”});
setQueryFilter(新的QueryFilter(“Name”,“=”,“someTS”));
QueryResponse testSetQueryResponse=restApi.query(testSetRequest);
System.out.println(“成功:“+testSetQueryResponse.wasSuccessful());
System.out.println(“大小:“+testSetQueryResponse.getTotalResultCount());
对于(int i=0;i0){
for(intj=0;jv2.0是未来的首选版本。下面的一些小调整应该会让你振作起来
与此相反(在1.43中工作,因为集合已返回):
int numberOfTestCases=testSetJsonObject.get(“TestCases”).getAsJsonArray().size();
如果(numberOfTestCases>0){
对于(int j=0;j 0){
QueryRequest testCaseRequest=新的QueryRequest(testSetJsonObject.getAsJsonObject(“TestCases”);
setFetch(新的Fetch(“FormattedID”);
//加载集合
JsonArray testCases=restApi.query(testCaseRequest.getResults();
对于(int j=0;j只要api版本为1.43,这应该可以工作。在v2.0中,集合不会在结果中返回,而是在对象中返回计数和集合url。可能是wsapi版本设置不正确吗?我运行了您的代码,没有得到任何错误……好吧,在Rally提供的示例中,他们向我们建议如果我将另一段代码更改为使用“1.43”,则使用api版本“v2.0”,那么它就不起作用了。但是这个特殊的类确实适用于1.43,并且带来了测试用例号。它在所有代码中是否都应该是相同的?我们有解决方案吗?我刚刚意识到返回的测试用例集合的顺序是错误的。在我的例子中,我需要保留测试集中测试用例的顺序。我看到了这个字段“DragAndDropRank”,但它是完全不可读的,类似这样。“P!”zG~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~那么如何按照web上显示的顺序返回测试用例集合?请尝试testCaseRequest.setOrder('DragAndDropRank'));方向也可能是DESC-不确定。我从一开始就尝试了这一点,但返回订单又回到了格式化的ID上。我怀疑这是一个错误。我们的QA自动化严重依赖于此订单,所以我不确定现在如何进行。我有屏幕截图显示Rally中的订单和来自Java的订单。你能提交一个案例吗h是否支持此信息?我能够重现您的问题,并且它似乎是WSAPI中的一个有效缺陷。
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();
}
}
}
}
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());
}
}