如何使用测试案例ID(TestRail Java Client)批量更新测试运行结果?

时间:2019-01-22 18:35:20

标签: testrail

如何使用TestRail Java Client使用测试用例ID批量更新测试运行结果?

这是来自add_results_for_cases()的API参考中的示例批量更新请求。

{
    "results": [
        {
            "case_id": 1,
            "status_id": 5,
            "comment": "This test failed",
            "defects": "TR-7"
        },
        {
            "case_id": 2,
            "status_id": 1,
            "comment": "This test passed",
            "elapsed": "5m",
            "version": "1.0 RC1"
        },
        ..
        {
            "case_id": 1,
            "assignedto_id": 5,
            "comment": "Assigned this test to Joe"
        }
        ..
    ]
}

1 个答案:

答案 0 :(得分:1)

API调用

public static void addResultsForCasesAllPass(int testRunId, int... testIds)
{
  APIClient client = new APIClient(BASE_URL);
  client.setUser(USER);
  client.setPassword(API_KEY);
  JSONArray response = null;
  try
  {
     Map data = new HashMap();
     List cases = new ArrayList();
     data.put("results", cases);
     for ( int testId : testIds )
     {
        Map singleCase = new HashMap();
        singleCase.put("case_id", "" + testId);
        singleCase.put("status_id", "" + 5);
        cases.add(singleCase);
     }
     String responseReq = JSONValue.toJSONString(data);
     Log.d(TAG, responseReq);

     Object object = 
        client.sendPost("add_results_for_cases/" 
            + testRunId, data);

     response = 
        (JSONArray) client.sendPost("add_results_for_cases/" 
            + testRunId, data);

     Log.d(TAG,"response = "+response.toJSONString());
  }
  catch ( IOException e )
  {
     e.printStackTrace();
  }
  catch ( APIException e )
  {
     e.printStackTrace();
  }
}

以及变量

public static final String USER = "firstName.lastName@company.com";
public static final String API_KEY = "/asdsdsd-k9yTR8cxxxxd5uj";
public static final String BASE_URL = "https://my.testRail.io/";

还记得通过测试栏上的admin标签启用API密钥