[PPJ_28] HttpRunnerManager用例配置-0
在HttpRunnerManager的【测试计划】模块下,有2个子模块:测试套件、定时任务

一、测试套件
测试套件:Test Suite,与之前提及的组合用例类似,可把单个接口用例按照业务逻辑进行组合执行。但组合用例不能包含组合用例,而测试套件可以包含组合用例,相当于组合套件是对组合用例更高一层的封装。
案例:
创建一个测试用例集suite_test_methods
,使其包含:测试用例test_get_request
、组合用例test_method_group
。然后,执行该测试用例集,观察返回的响应结果
方式1:同步执行
同步执行完成之后会立即生成测试报告,并自动展示报告的内容
创建测试用例集:



执行用例(同步方式):

执行结果:


从上可知,本次创建的测试套件可成功执行,加载的测试套件也可自由调整执行顺序,相关的数据配置会自动从用例的配置中读取
方式2:异步执行
异步执行是在服务后台进行执行测试用例,在执行异步方式之前,首先需要确保启动支持异步的相关服务项:RabbitMQ Service、worker、celery任务监控后台
1)启动RabbitMQ Service

2)在HttpRunnerManager目录,启动worker
python manage.py celery -A HttpRunnerManager worker --loglevel=info

3)启动celery任务监控后台
Celery:是一个异步任务队列(基于分布式消息传递的作业队列),其侧重于实时操作,且对调度支持效果也很好,因此Celery通常用于生产系统每天处理数以百万计的任务。
Celery虽然是用Python所编写,但该协议可在任意语言实现,可与其他语言通过webhooks实现。
操作命令:
celery flower

4)执行用例(异步方式)


执行结果:
在模块 报告管理 --> 查看报告:可查看本次异步执行用例所生成的测试报告

点击测试报告的名称,可打开测试报告的详情记录

同时,也可点击下载该测试报告,格式为.html

二、定时任务
测试套件也支持定时任务,便于进行回归测试。定时任务需要启动定时任务的监听器,操作命令如下:
python manage.py celery beat --loglevel=info

操作:测试计划 --> 定时任务 --> 新增任务 --> 系统设置 --> 按照设置的定时控制执行用例 --> 查看所设置间隔生成的测试报告
新增定时任务

系统设置:定时配置

执行定时任务的用例:

执行结果:查看生成的测试报告(报告生成频率:1min/次)

【附】Crontab格式
通过Crontab命令,可在固定的间隔时间执行指定的系统命令or脚本(shell script)。时间间隔的单位可为:<分钟--小时--天--月--星期> 5个域进行的任意组合,每个域之间用空格分隔
分钟 | 时 | 天 | 月 | 星期 | |
---|---|---|---|---|---|
取值 | 0~59 | 0~23 | 1~31 | 1~12 | 0~7 |
0:凌晨 | 0,7:星期天 |
e.g.:
每隔1min执行一次: * * * * *
每30min执行一次: */30 * * * *
每1h执行一次: * */1 * * *
没周一到周五早上8点都执行一次: * 8 * * 1-5
参考资料:详解cron表达式