用户用例操作
场景描述
该场景适用于已在测试计划中创建对接自己的用户服务的Testhub服务的用户,创建后在测试计划界面管理用例。
下面介绍如何新建用例,以及对用例的删改查操作。
前提条件
需要用户成功注册自己的Testhub服务。
涉及接口
用户用例操作包括,创建测试用例、更新测试用例、批量删除测试用例、获取测试用例详情、批量执行用例接口、批量更新测试用例结果,涉及接口如下:
- 创建自定义测试服务类型用例:新建用例进行测试。
- 更新自定义测试服务类型用例:修改用例信息。
- 批量删除自定义测试服务类型用例:可同时删除多个用例。
- 获取测试用例详情:单个查询用例详情。
- 批量执行测试用例:同时执行多个测试用例。
- 批量更新测试用例结果:用例结果产生后,同时更新多个测试用例结果。
操作步骤
- 确定调用API鉴权时使用的Token。
- 查询token,详情请参见获取用户Token。
- 获取响应Header参数中X-Subject-Token对应的值。
- 创建新的测试用例。
- 接口相关信息
URL格式:POST /v1/projects/{project_id}/testcases
接口请求参数说明详情,请参见创建自定义测试服务类型用例。
- 请求示例
POST https://{endpoint}/v1/projects/{project_id}/testcases
- {endpoint}信息请从终端节点获取。
- {project_id}为项目唯一标识。
Body:
{ "name" : "testcaseXXX", "service_id" : 13, "rank_id" : "2", "testcase_number" : "1234", "extend_info" : { "description" : "这是一条描述信息", "preparation" : "这是一条前置条件xxxxxx", "steps" : [ { "expect_result" : "<ol class=\"ordered\"><li class=\"ordered\"><span>结果一</span></li><li class=\"ordered\"><span>结果二</span></li></ol><p><br /></p>", "test_step" : "<p>步骤一</p>" } ], "label_list" : [ "标签一", "标签二" ], "module_id" : "b66aab5469cc4ab39b0dda8e644a42a4", "test_version_id" : "8.1.2", "fix_version_id" : "8.2.0.1", "assigned_id" : "b66aab5469cc4ab39b0dda8e644a42a4", "issue_id" : "b66aab5469cc4ab39b0dda8e644a42a4" } }
- 响应示例
{ "testcase_id" : "efdb403066474ab08836b9eeaaa23bca", "project_id" : "aswe4w5ty4032344tgse345eeaaa23bc", "service_id" : 13, "name" : "这是一个测试计划名称", "testcase_number" : "1234", "rank_id" : "2", "status_id" : "0", "assigned_user" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" }, "execute_count" : 3, "result_id" : "0", "extend_info" : { "author" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx", "time" : "2020-06-09 16:55:57" }, "updator" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx", "time" : "2020-06-09 16:55:57" }, "domain" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" }, "description" : "这是一条描述信息", "preparation" : "这是一条前置条件xxxxxx ", "steps" : [ { "expect_result" : "<ol class=\"ordered\"><li class=\"ordered\"><span>结果一</span></li><li class=\"ordered\"><span>结果二</span></li></ol><p><br /></p>", "test_step" : "<p>步骤一</p>" } ], "label_list" : [ { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" } ], "defect_list" : [ { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" } ], "module" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" }, "issue" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" }, "test_version_id" : "string", "fixed_version" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" } } }
- 接口相关信息
- 确定用例创建成功后,可对用例进行删改查操作。
- 查询用例详情:
- 接口相关信息
URL格式:GET /v1/projects/{project_id}/testcases/{testcase_id}
接口请求参数说明详情,请参见获取测试用例详情。
- 请求示例
GET https://{endpoint}/v1/projects/{project_id}/testcases/{testcase_id}
- {endpoint}信息请从终端节点获取。
- {project_id}为项目唯一标识。
- {testcase_id}为用例唯一标识。
Body:无
- 响应示例
{ "testcase_id" : "efdb403066474ab08836b9eeaaa23bca", "project_id" : "aswe4w5ty4032344tgse345eeaaa23bc", "service_id" : 13, "name" : "这是一个测试计划名称", "testcase_number" : "1234", "rank_id" : "2", "status_id" : "0", "assigned_user" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" }, "execute_count" : 3, "result_id" : "0", "extend_info" : { "author" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx", "time" : "2020-06-09 16:55:57" }, "updator" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx", "time" : "2020-06-09 16:55:57" }, "domain" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" }, "description" : "这是一条描述信息", "preparation" : "这是一条前置条件xxxxxx ", "steps" : [ { "expect_result" : "<ol class=\"ordered\"><li class=\"ordered\"><span>结果一</span></li><li class=\"ordered\"><span>结果二</span></li></ol><p><br /></p>", "test_step" : "<p>步骤一</p>" } ], "label_list" : [ { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" } ], "defect_list" : [ { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" } ], "module" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" }, "issue" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" }, "test_version_id" : "string", "fixed_version" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" } } }
- 接口相关信息
- 修改用例详情:
- 接口相关信息
URL格式:PUT /v1/projects/{project_id}/testcases/{testcase_id}
接口请求参数说明详情,请参见更新自定义测试服务类型用例。
- 请求示例
PUT https://{endpoint}/v1/projects/{project_id}/testcases/{testcase_id}
- {endpoint}信息请从终端节点获取。
- {project_id}为项目唯一标识。
- {testcase_id}为用例唯一标识。
Body:
{ "name" : "testcaseXXX", "service_id" : 13, "rank_id" : "2", "testcase_number" : "191", "extend_info" : { "description" : "这是一条描述信息", "preparation" : "这是一条前置条件xxxxxx", "steps" : [ { "expect_result" : "<ol class=\"ordered\"><li class=\"ordered\"><span>结果一</span></li><li class=\"ordered\"><span>结果二</span></li></ol><p><br /></p>", "test_step" : "<p>步骤一</p>" } ], "label_list" : ["标签一", "标签二" ], "module_id" : "b66aab5469cc4ab39b0dda8e644a42a4", "test_version_id" : "8.1.2", "fix_version_id" : "8.2.0.1", "assigned_id" : "b66aab5469cc4ab39b0dda8e644a42a4", "issue_id" : "b66aab5469cc4ab39b0dda8e644a42a4", "status_id" : "0", "defect_id_list" : [ " b66aab5469cc4ab39b0dda8e644a42a4", " efdb403066474ab08836b9eeaaa23bca " ] } }
- 响应示例
{ "testcase_id" : "efdb403066474ab08836b9eeaaa23bca", "project_id" : "aswe4w5ty4032344tgse345eeaaa23bc", "service_id" : 13, "name" : "这是一个测试计划名称", "testcase_number" : "1234", "rank_id" : "2", "status_id" : "0", "assigned_user" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" }, "execute_count" : 3, "result_id" : "0", "extend_info" : { "author" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx", "time" : "2020-06-09 16:55:57" }, "updator" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx", "time" : "2020-06-09 16:55:57" }, "domain" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" }, "description" : "这是一条描述信息", "preparation" : "这是一条前置条件xxxxxx ", "steps" : [ { "expect_result" : "<ol class=\"ordered\"><li class=\"ordered\"><span>结果一</span></li><li class=\"ordered\"><span>结果二</span></li></ol><p><br /></p>", "test_step" : "<p>步骤一</p>" } ], "label_list" : [ { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" } ], "defect_list" : [ { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" } ], "module" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" }, "issue" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" }, "test_version_id" : "string", "fixed_version" : { "id" : "efdb403066474ab08836b9eeaaa23bca", "name" : "name_xxxxxx" } } }
- 接口相关信息
- 删除用例详情:
- 接口相关信息
URL格式:POST /v1/projects/{project_id}/testcases/batch-delete
接口请求参数说明详情,请参见批量删除自定义测试服务类型用例。
- 请求示例
POST https://{endpoint}/v1/projects/{project_id}/testcases/batch-delete
{endpoint}信息请从终端节点获取。
{project_id}为项目唯一标识。
Body:
{ "service_id" : 13, "testcase_id_list" : [ "efdb403066474ab08836b9eeaaa23bca", "251fca07b22f493692eb06b1754f07a8" ] }
- 响应示例
{ "error_code" : "CLOUDTEST.000XXXXXX", "error_msg" : "失败原因XXXXX", "error_detail" : { "failed" : [ { "error_code" : "CLOUDTEST.000XXXXXX", "error_msg" : "失败原因XXXXX", "testcase_id" : "efdb403066474ab08836b9eeaaa23bca" } , { "error_code" : "CLOUDTEST.000XXXXXX", "error_msg" : "失败原因XXXXX", "testcase_id" : "251fca07b22f493692eb06b1754f07a8" }] } }
- 接口相关信息
- 查询用例详情:
- 确定用例创建成功且无需修改后,可执行用例并更新用例结果。
- 接口相关信息
URL格式:POST /v1/projects/{project_id}/testcases/execution
接口请求参数说明详情,请参见批量执行测试用例。
- 请求示例
POST https://{endpoint}/v1/projects/{project_id}/testcases/execution
- {endpoint}信息请从终端节点获取。
- {project_id}为项目唯一标识。
Body:
{ "service_id": 13, "plan_id": "b66aab5469cc4ab39b0dda8e644a42a4", "execute_list": [ { "testcase_id": "b66aab5469cc4ab39b0dda8e644a42a4", "execute_id": "efdb403066474ab08836b9eeaaa23bca", "result_id": "0", "start_time": 2020-06-2218: 11: 54 } ] }
- 响应示例
{ "error_code" : "CLOUDTEST.000XXXXXX", "error_msg" : "失败原因XXXXX", "error_detail" : { "failed" : [ { "error_code" : "CLOUDTEST.000XXXXXX", "error_msg" : "失败原因XXXXX", "testcase_id" : "efdb403066474ab08836b9eeaaa23bca" } , { "error_code" : "CLOUDTEST.000XXXXXX", "error_msg" : "失败原因XXXXX", "testcase_id" : "251fca07b22f493692eb06b1754f07a8" }] } }
- 接口相关信息
- 等待用例脚本在用户服务处执行完毕后,需要调用接口将执行结果通过接口返回到用户的Testhub服务同步数据。批量更新测试用例结果
- 接口相关信息
URL格式:POST /v1/projects/{project_id}/testcases/result
接口请求参数说明详情,请参见批量更新测试用例结果。
- 请求示例
POST https://{endpoint}/v1/projects/{project_id}/testcases/result
- {endpoint}信息请从终端节点获取。
- {project_id}为项目唯一标识。
Body:
{ "service_id": 13, "execute_list": [ { "testcase_id": "b66aab5469cc4ab39b0dda8e644a42a4", "execute_id": "efdb403066474ab08836b9eeaaa23bca", "result_id": "0", "end_time": 2020-06-23 18: 11: 54, "duration": 120, "description": "这是一条备注信息" } ] }
- 响应示例
{ "error_code" : "CLOUDTEST.000XXXXXX", "error_msg" : "失败原因XXXXX", "error_detail" : { "failed" : [ { "error_code" : "CLOUDTEST.000XXXXXX", "error_msg" : "失败原因XXXXX", "testcase_id" : "efdb403066474ab08836b9eeaaa23bca" } , { "error_code" : "CLOUDTEST.000XXXXXX", "error_msg" : "失败原因XXXXX", "testcase_id" : "251fca07b22f493692eb06b1754f07a8" }] } }
- 接口相关信息