Java Rally REST API:如何创建新的测试用例

时间:2017-01-04 16:35:37

标签: java rest rally testcase

我已经能够通过Rally API成功创建测试结果,但现在我想创建一个测试用例,如果Rally中还没有。

我收到来自Rally的错误“对象ID为空”,这意味着Rally认为我正在更新测试用例,即使我正在尝试创建一个。

有没有人尝试过创建测试用例Rally API,或者有人看到我需要修复的内容吗? 谢谢!

//Method to build the JSON and create the new test CASE in Rally
    public static void createNewTestCase(String currentMethodName) 
    throws URISyntaxException, IOException{
        Configuration conf = new Configuration();
        RallyRestApi restApi = new RallyRestApi(new URI(
        "https://rally1.rallydev.com"),
        {authentication code});
        restApi.setApplicationName("Test Case");             
         try {
                //Create test case
                JsonObject newTestCase = new JsonObject();
                newTestCase.addProperty("Name", currentMethodName);
                newTestCase.addProperty("Description", "Created by Rally");
                newTestCase.addProperty("Project", "Project1"));
                newTestCase.addProperty("Type", "Functional");
                newTestCase.addProperty("Method", "Automated");
                newTestCase.addProperty("DefectStatus", "NONE");
            CreateRequest createRequest = new CreateRequest("testcase",
                newTestCase);
            CreateResponse createResponse = restApi.create(createRequest);
                if (createResponse.wasSuccessful()){
                System.out.println("Test case created successfully");
                }
                else {
                System.out.println("The test case could not be created");
                String[] createErrors;
                createErrors = createResponse.getErrors();
                System.out.println("Error occurred creating Test Case: ");
                for (int i=0; i<createErrors.length;i++) {
                   System.out.println(createErrors[i]);
               }
                }

         }catch (Exception e){
                e.printStackTrace();
         }
         finally {
                restApi.close();
         }
   }

1 个答案:

答案 0 :(得分:1)

我的猜测是问题在于设置项目。 Rally中的对象关系始终表示为refs:/type/objectid

newTestCase.addProperty("Project", "/project/12345");