性能测试工具之--Molotov

Molotov是一款基于Python的性能测试工具。它的使用与Locust比较接近,但它并不提供界面。

安装:pip install molotov,GitHub地址:https://github.com/loads/molotov

官方文档:https://molotov.readthedocs.io/en/stable/

被测接口来自:https://github.com/defnngj/learning-API-test

例子:

1、创建脚本 loadtest.py

"""
molotov 性能测试脚本
"""
from molotov import scenario

_API = 'http://127.0.0.1:5000/'


@scenario(weight=40)
async def scenario_one(session):
"""测试默认接口(get)"""
async with session.get(_API) as resp:
res = await resp.json()
assert resp.status == 200
assert res['code'] == 10200
assert res['message'] == 'Welcome to API testing'


@scenario(weight=60)
async def scenario_two(session):
"""添加用户信息接口(post->JSON)"""
payload = {"name": "jack", "age": 22, "height": 177}
async with session.post(_API + "add_user", json=payload) as resp:
res = await resp.json()
assert resp.status == 200
assert res['code'] == 10200
assert res['message'] == 'add success'

2、运行

molotov loadtest.py -w 10 -r 100

主要参数:

  • -w 指定worker的虚拟用户。

  • -r 指定每个虚拟用户的请求个数。

  • -d 指定运行的时长。

  • -q 静默情况执行。

  • -x 当出现失败时停止。

posted @ 2020-01-14 16:10  YanaMay  阅读(373)  评论(0)    收藏  举报