2012-09-12 140 views

回答

1

测试案例通过WSAPI中TestSet的TestCases集合与测试集相关联。此代码示例演示如何创建一些测试用例,然后创建与新创建的测试用例关联的测试集。

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(); 
} 
相关问题