【问题标题】:How to bulk update test run results with test case IDs (TestRail Java Client)?如何使用测试用例 ID(TestRail Java 客户端)批量更新测试运行结果?
【发布时间】:2019-01-22 18:35:20
【问题描述】:

如何使用 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"
        }
        ..
    ]
}

【问题讨论】:

    标签: testrail


    【解决方案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 密钥

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-21
      • 1970-01-01
      • 2019-03-20
      • 2018-12-20
      • 2019-11-27
      相关资源
      最近更新 更多