httprunner简介
httprunner是http测试框架,实现自动化测试、性能测试、线上监控、持续集成等多种测试需求
设计理念
约定优于配置
投入>产出比很重要
开源,依赖requests ,pytest ,pydantic ,allure 和 locust
特点
继承强大功能的requests ,只要处理HTTP(S)
yaml/json定义测试用
har 支持下记录并生成测试用例
支持variables/ extract/ validate/hooks机制,创建非常复杂的测试方案
debugtalk.py插件,任何功能都可以在测试用例的任何部分使用
jmespath ,提取和验证json响应
pytest ,数百个插件
allure ,测试报告
重复使用locust ,进行性能测试,无需额外的工作
支持CLI命令,与CI/CD完美结合
安装
httprunner是用Python开发的
Python3.6/3.7/3.8,支持GitHub-ActionsmacOS/Linux/Windows
安装
# pip安装
pip3 install httprunner
# github 安装
pip3 install git+https://github.com/httprunner/httprunner.git@master
# 升级
pip3 install -U httprunner
pip3 install -U git+https://github.com/httprunner/httprunner.git@master
安装后自带的五个命令
httprunner所有功能
主命令,用于所有功能
hrun运行测试用例
指令httprunner run的别名,用于运行yaml/json/pytest 测试用例
hmake,yaml/json用例转换成pytest用例
httprunner make的别名,将yaml/json用例转换成pytest用例
har2case,har转 yaml/json 用例
指令httprunner har2case的别名,将HAR文件转换成 yaml/json 用例
locust性能测试
利用locust 运行性能测试。
locust是单独的命令,locust运行开始时,monkey patch ssl避免递归错误
基本命令
# 查看版本
hrun -V
# 查看版本
httprunner -V
3.1.0
# 帮助
httprunner -h
usage: httprunner [-h] [-V] {run,startproject,har2case,make} ...
One-stop solution for HTTP(S) testing.
positional arguments:
{run,startproject,har2case,make}
sub-command help
run Make httprunner testcases and run with pytest.
startproject Create a new project with template structure.
har2case Convert HAR(HTTP Archive) to yaml/json testcases for
httprunner.
make Convert yaml/json testcases to pytest cases.
optional arguments:
-h, --help show this help message and exit
-V, --version show version