如何更新Rally中的测试用例步骤

时间:2014-03-07 12:37:36

标签: java rally

我正在尝试更新Rally测试用例。我能够更新现有的测试用例名称,我也想更新测试步骤。是否可以在Rally中更新现有的测试步骤? 我尝试了以下代码,并成功更新了测试用例'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)

此致 基兰

1 个答案:

答案 0 :(得分:0)

是的,这是可能的。 看起来您缺少必需的StepIndex字段的值。 TestCaseStep默认有两个必填字段:一个是TestCase,另一个是StepIndex。在这个例子中,我已经在这个TestCase上有一步(使用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();
        }