如何使用测试用例 ID 批量更新测试运行结果TestRail
Java Client
?
下面是来自 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"
}
..
]
}
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密钥