基于httprunner的接口测试

环境:Ubuntu

  • 安装

sudo pip3 install httprunner==2.5.7

在 HttpRunner 安装成功后,系统中会新增如下 5 个命令:

    httprunner: 核心命令
    ate: 曾经用过的命令(当时框架名称为 ApiTestEngine),功能与 httprunner 完全相同
    hrun: httprunner 的缩写,功能与 httprunner 完全相同
    locusts: 基于 Locust 实现性能测试
    har2case: 辅助工具,可将标准通用的 HAR 格式(HTTP Archive)转换为YAML/JSON格式的测试用例

  • 实例操作

TesterHome 登录

功能描述:

  • 进入登录页面
  • 输入账号和密码
  • 点击【Sign In】进行登录

Charles 抓包生成 HAR 文件

 

点击文件, 导出session,保存为har格式。

转化为yaml文件

har2case docs/data/testerhome-login.har -2y

 

执行

生成html格式的report,在reports目录下

$ hrun testerhome-sign_in.yml 
INFO     HttpRunner version: 2.5.7
INFO     Start to run testcase: testcase description
/account/sign_in
INFO     GET https://testerhome.com/account/sign_in
INFO     status_code: 200, response_time(ms): 179.4 ms, response_length: 12115 bytes

.
/account/sign_in
INFO     POST https://testerhome.com/account/sign_in
INFO     status_code: 200, response_time(ms): 231.92 ms, response_length: 89 bytes

.
/
INFO     GET https://testerhome.com/
INFO     status_code: 200, response_time(ms): 157.67 ms, response_length: 51701 bytes

.

----------------------------------------------------------------------
Ran 3 tests in 0.577s

OK
INFO     Start to render Html report ...
INFO     Generated Html report: ./reports/20200610T031226.611388.html
Sentry is attempting to send 0 pending error messages
Waiting up to 2 seconds
Press Ctrl-C to quit
$ 

 

性能测试:

HttpRunner 通过复用 Locust,可以在无需对 YAML/JSON 进行任何修改的情况下,直接运行性能测试。

$ locusts -f example-api-test.yml --processes 4
HttpRunner version: 2.5.7
[2020-06-10 11:18:20,853] wuzhiguo-Lenovo-B490/INFO/locust.main: Starting web monitor at http://*:8089
[2020-06-10 11:18:20,854] wuzhiguo-Lenovo-B490/INFO/locust.main: Starting Locust 0.14.6
[2020-06-10 11:18:20,877] wuzhiguo-Lenovo-B490/INFO/locust.main: Starting Locust 0.14.6
[2020-06-10 11:18:20,877] wuzhiguo-Lenovo-B490/INFO/locust.main: Starting Locust 0.14.6
[2020-06-10 11:18:20,877] wuzhiguo-Lenovo-B490/INFO/locust.main: Starting Locust 0.14.6
[2020-06-10 11:18:20,878] wuzhiguo-Lenovo-B490/INFO/locust.main: Starting Locust 0.14.6

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值