说明,可以直接在某个视图集定义自定义接口来验证。
调试1:前端界面直接编写yaml文件.
- 新增要实现存数据到mysql,同时存文件到testcase下, 如test.yaml
- 更新yaml数据,同时做到更新 testcase下的文件,如test.yaml

python
@action(methods=['GET'], detail=True, url_path='mkfile')
def mkfile_case(self,req,pk):
# student = self.get_object()
yaml_file = 'key: value\nlist:\n - item1\n - item2'
yaml_name = 'test.yaml'
yaml_path = os.path.join('testcase', yaml_name)
with open(yaml_path, 'w') as f:
f.write(yaml_file)
return ResponseList(msg="make success")

调试2 :后端实现单用例的执行

python
@action(methods=["get"],detail=True)
def run_case(self,request,pk):
# student2 = Student.objects.get(pk=pk)
# 这个写法同上
student = self.get_object()
path =f"testcase/{student.desc}"
# 2.调用hr4的api,来执行我们的json文件
# print(path)
exit_code = main_run([path])
# 3.返回执行结果
if exit_code != 0:
return ResponseError(msg="failed run case")
# 4.返回执行结果
return ResponseList(msg="run success")

调试3:后端实现多个用例的执行,并生成报告
后端:

前端:
一个测试计划可以选多个测试用例,然后点击执行,就运行多个测试用例
在测试报告菜单中,可以展示每个测试计划执行后的测试结果。

