2
votes

I want to add Test cases (already present in Rally in Test folders) into a newly created Test sets using Java Rally Rest API. Basically every time I want to execute the test cases through Rally I need to create new Test sets and add relevant test cases ( either priority wise, automated/ Manual) in test sets. Any help on this would be of great help.

1

1 Answers

1
votes

Test cases are associated to test sets via the TestCases collection on TestSet in the WSAPI. This code example demonstrates creating a few test cases and then creating a test set associated with the newly created test cases.

RallyRestApi restApi = new RallyRestApi(new URI(SERVER),
    USERNAME, PASSWORD);

try {

    //Create some test cases
    JsonArray testCases = new JsonArray();
    for(int i = 0; i < 3; i++) {
        JsonObject newTestCase = new JsonObject();
        newTestCase.addProperty("Name", "New Test Case " + i);
        CreateRequest createRequest = new CreateRequest("testcase", newTestCase);
        CreateResponse createResponse = restApi.create(createRequest);
        String ref = createResponse.getObject().get("_ref").getAsString();
        System.out.println(String.format("Created test case %s", ref));

        //Keep track of the test case
        JsonObject testCase = new JsonObject();
        testCase.addProperty("_ref", ref);
        testCases.add(testCase);
    }

    //Create test set
    JsonObject newTestSet = new JsonObject();
    newTestSet.addProperty("Name", "New Test Set");
    newTestSet.add("TestCases", testCases);
    CreateRequest createRequest = new CreateRequest("testset", newTestSet);
    CreateResponse createResponse = restApi.create(createRequest);
    System.out.println(String.format("Created test set %s", createResponse.getObject().get("_ref").getAsString()));

} finally {
    //Release all resources
    restApi.close();
}