gpt4 book ai didi

Rally:如何使用 REST API 将测试用例与用户故事进行映射?

转载 作者:行者123 更新时间:2023-12-02 03:31:52 25 4
gpt4 key购买 nike

我正在编写代码以使用 rally restAPI 创建新的测试用例。能够在测试计划和测试文件夹下创建测试用例。现在,想要将这些测试用例映射到 Rally 用户故事。

工作产品是映射它的领域。但是如何使用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();
}
}
}

关于Rally:如何使用 REST API 将测试用例与用户故事进行映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26144335/

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