3
我正在编写使用拉力赛restAPI创建新测试用例的代码。 能够根据测试计划&测试文件夹创建测试用例。 现在,想要将这些测试用例映射到Rally用户故事。Rally:如何使用REST API将测试用例与用户素材进行映射?
工作产品是映射它的字段。但是如何使用restAPI获取用户故事的参考?
如果有人在过去做过,请让我知道。
我正在编写使用拉力赛restAPI创建新测试用例的代码。 能够根据测试计划&测试文件夹创建测试用例。 现在,想要将这些测试用例映射到Rally用户故事。Rally:如何使用REST API将测试用例与用户素材进行映射?
工作产品是映射它的字段。但是如何使用restAPI获取用户故事的参考?
如果有人在过去做过,请让我知道。
在WS API用户故事中是HierarchicalRequirement
对象。查询故事,你想成为一个工作产品,并得到它的_ref
。然后更新测试用例,例如
testCaseUpdate.addProperty("WorkProduct", storyRef);
下面是使用Rally Rest toolkit for Java一个Java例子,但方法是一样的,不管你选择语言或工具包的:
public class UpdateTestCase {
public static void main(String[] args) throws URISyntaxException, IOException {
String host = "https://rally1.rallydev.com";
String apiKey = "_abc123";
String workspaceRef = "/workspace/123456";
String applicationName = "RestExample_updateWorkProductOnTestCase";
RallyRestApi restApi = new RallyRestApi(new URI(host),apiKey);
restApi.setApplicationName(applicationName);
try {
String testid = "TC12";
String storyid = "US34";
QueryRequest testCaseRequest = new QueryRequest("TestCase");
testCaseRequest.setWorkspace(workspaceRef);
testCaseRequest.setFetch(new Fetch("FormattedID", "Name", "WorkProduct"));
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", testid));
QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);;
if (testCaseQueryResponse.getTotalResultCount() == 0) {
System.out.println("Cannot find test case : " + testid);
return;
}
JsonObject testCaseJsonObject = testCaseQueryResponse.getResults().get(0).getAsJsonObject();
String testCaseRef = testCaseJsonObject.get("_ref").getAsString();
System.out.println(testCaseRef);
QueryRequest storyRequest = new QueryRequest("HierarchicalRequirement");
storyRequest.setWorkspace(workspaceRef);
storyRequest.setFetch(new Fetch("FormattedID", "Name"));
storyRequest.setQueryFilter(new QueryFilter("FormattedID", "=", storyid));
QueryResponse storyQueryResponse = restApi.query(storyRequest);;
if (storyQueryResponse.getTotalResultCount() == 0) {
System.out.println("Cannot find test story : " + storyid);
return;
}
JsonObject storyJsonObject = storyQueryResponse.getResults().get(0).getAsJsonObject();
String storyRef = storyJsonObject.get("_ref").getAsString();
System.out.println(storyRef);
JsonObject testCaseUpdate = new JsonObject();
testCaseUpdate.addProperty("WorkProduct", storyRef);
UpdateRequest updateTestCaseRequest = new UpdateRequest(testCaseRef,testCaseUpdate);
UpdateResponse updateTestCaseResponse = restApi.update(updateTestCaseRequest);
if (updateTestCaseResponse.wasSuccessful()) {
System.out.println("Successfully updated : " + testid + " WorkProduct after update: " + testCaseUpdate.get("WorkProduct"));
}
} finally {
restApi.close();
}
}
}