2014-03-07 42 views
0

我正在嘗試更新拉力賽測試用例。我能夠更新現有的測試用例名稱,我也想更新測試步驟。是否有可能更新拉力賽現有的測試步驟? 我試過下面的代碼,併成功地更新了測試用例'name',但不是測試步驟如何更新拉力賽測試用例步驟

感謝您在這方面的幫助。

private void updateTestCase 
{ 
    JsonObject newTestCase = new JsonObject(); 
    newTestCase.addProperty("Name", 
      "Latest case to add Test Case Attributes"); 
    newTestCase.addProperty("Method", "Automated"); 
    CreateRequest createRequest = new CreateRequest("testcase", newTestCase); 
    CreateResponse response = restApi.create(createRequest); 
    System.out.println(response.toString()); 
    JsonObject json = response.getObject(); 
    System.out.println(json); 

    JsonObject updatedName = new JsonObject(); 
    updatedName.addProperty("Name", "Test Case Name newly Updated"); 

    // String testCaseObjectId = json.get("ObjectID").getAsString(); 
    String testCaseObjectId = "17456494683"; 
    UpdateRequest updateTestCase = new UpdateRequest("/testcase/" 
      + testCaseObjectId, updatedName); 
    UpdateResponse updateTCResponse = restApi.update(updateTestCase); 

    if (updateTCResponse.wasSuccessful()) { 
     System.out.println("Tag succeccfully added to the test case"); 
    } 

    JsonObject stepOne = new JsonObject(); 
    JsonObject stepTwo = new JsonObject(); 

    // Update test case for the test case 
    stepOne.addProperty("Input", "Open Database Connection"); 
    stepOne.addProperty("TestCase", "/testcase/" + testCaseObjectId); 
    stepTwo.addProperty("Input", "Verify the Target Schema Specified"); 
    stepTwo.addProperty("TestCase", "/testcase/" + testCaseObjectId); 

    UpdateRequest stepUpdateRequest1 = new UpdateRequest("TestCaseStep", 
      stepOne); 
    restApi.update(stepUpdateRequest1); 
    UpdateRequest createUpdateRequest2 = new UpdateRequest("TestCaseStep", 
      stepTwo); 
    restApi.update(createUpdateRequest2); 
} 

我收到以下錯誤:

Exception in thread "main" java.lang.NullPointerException: key == null 
at com.google.gson.internal.LinkedTreeMap.put(LinkedTreeMap.java:92) 
at com.google.gson.JsonObject.add(JsonObject.java:57) 
at com.rallydev.rest.request.UpdateRequest.getBody(UpdateRequest.java:41) 
at com.rallydev.rest.RallyRestApi.update(RallyRestApi.java:189) 
at com.rallydev.rest.RallyRestApi.update(RallyRestApi.java:185) 
at com.ags.rally.App.createTestCase(App.java:169) 
at com.ags.rally.App.main(App.java:102) 

問候, 基蘭

+0

任何一個可以請讓我知道,如果測試步驟更新用是可能的嗎? – kiran

回答

0

是的,它是可能的。 它看起來像缺少必需的StepIndex字段的值。 TestCaseStep默認有兩個必填字段:一個是TestCase,另一個是StepIndex。在這個例子中我已經在這個測試用例(與StepIndex 0)一步到位,所以StepIndex分別設置爲1和2:

QueryRequest testCaseRequest = new QueryRequest("TestCase"); 
     testCaseRequest.setFetch(new Fetch("FormattedID","Name", "Steps")); 
     testCaseRequest.setWorkspace(workspaceRef); 
     testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TC6")); 
     QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest); 
     JsonObject testCaseJsonObject = testCaseQueryResponse.getResults().get(0).getAsJsonObject(); 

     String testCaseRef = testCaseJsonObject.get("_ref").getAsString(); 
     int numberOfSteps = testCaseJsonObject.getAsJsonObject("Steps").get("Count").getAsInt(); 
     System.out.println(testCaseJsonObject.get("Name") + " ref: " + testCaseRef + "number of steps: " + numberOfSteps + " " + testCaseJsonObject.get("Steps")); 

     try { 
      JsonObject stepOne = new JsonObject(); 
      JsonObject stepTwo = new JsonObject(); 
      stepOne.addProperty("Input", "Open Database Connection"); 
      stepOne.addProperty("StepIndex", 1); 
      stepTwo.addProperty("StepIndex", 2); 
      stepOne.addProperty("TestCase", testCaseRef); 
      stepTwo.addProperty("Input", "Verify the Target Schema Specified"); 
      stepTwo.addProperty("TestCase", testCaseRef); 
      CreateRequest createRequest = new CreateRequest("testcasestep", stepOne); 
      CreateResponse createResponse = restApi.create(createRequest); 
      CreateRequest createRequest2 = new CreateRequest("testcasestep", stepTwo); 
      CreateResponse createResponse2 = restApi.create(createRequest2); 

     } finally { 
      restApi.close(); 
     } 
+0

感謝Nick提供的答覆。我試過你用step索引代碼。但是我看到這些步驟被添加爲新的testsstep,並且不更新現有的測試步驟。有什麼方法可以替代現有的測試步驟。最初,當我運行代碼時,我有5個測試步驟,當我運行代碼時,我可以看到6個步驟 – kiran

+0

如果在指定的StepIndex中沒有預先存在的步驟,則此代碼創建一個步驟,並且如果步驟已經存在,則用新值更新現有步驟在指定的StepIndex處。相同的代碼剛剛更新StepIndex 1和2與新的輸入值的兩個步驟 – nickm

+0

謝謝尼克我已經嘗試了不同的方法,並能夠 – kiran

相關問題