Rally: How to map test cases to user stories using the REST API?

I am writing code to create new test cases using rally restAPI. Ability to create test cases in the Test Plan and Test folder. Now you need to match these test cases to the Rally user stories.

The work product is the field for displaying it. But how do I get a link to the user's history using restAPI?

Please let me know if anyone has done this in the past.


source to share

1 answer

There is an object in the WS API user history HierarchicalRequirement

. Request a story that you want to become a work product and get it _ref

. Then update your test case eg.

testCaseUpdate.addProperty("WorkProduct", storyRef);


Here's a Java example using the Rally Rest Tool for Java , but the approach is the same regardless of your choice of language or toolkit:

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);

        try {
            String testid = "TC12";
            String storyid = "US34";

            QueryRequest testCaseRequest = new QueryRequest("TestCase");
            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);
            JsonObject testCaseJsonObject = testCaseQueryResponse.getResults().get(0).getAsJsonObject();
            String testCaseRef = testCaseJsonObject.get("_ref").getAsString();

            QueryRequest storyRequest = new QueryRequest("HierarchicalRequirement");
            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);
            JsonObject storyJsonObject = storyQueryResponse.getResults().get(0).getAsJsonObject();
            String storyRef = storyJsonObject.get("_ref").getAsString();

            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 {




All Articles