1

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

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

{
    "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"
        }
        ..
    ]
}
4

1 回答 1

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/";

还记得通过测试轨道站点中的管理选项卡启用 API 密钥

于 2019-01-22T18:35:43.570 回答