Rally:如何使用REST API映射包含用户故事的测试用例?

时间:2014-10-01 14:58:30

标签: rally

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

工作产品是映射它的字段。但是如何使用restAPI获取用户故事的参考?

如果有人过去做过,请告诉我。

1 个答案:

答案 0 :(得分:1)

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