2014-03-07 65 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

相关问题