性能測(cè)試工具

1.性能測(cè)試工具:

1.LoadRunner

2.JMeter

3.Locust

4.Molotov

https://mp.weixin.qq.com/s/Sm9OAnd0k8_E-I7Se2TlbQ

安裝

GitHub:https://github.com/loads/molotov

安裝:

pip install molotov

文檔:https://molotov.readthedocs.io/en/stable/

例子

我們來進(jìn)行接口測(cè)試,創(chuàng)建創(chuàng)建腳本loadtest.py。

"""

molotov 性能測(cè)試腳本"""

from molotovimport scenario

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

@scenario(weight=40)

async def scenario_one(session):

"""測(cè)試默認(rèn)接口(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'


weight表示接口的虛擬用戶權(quán)重。比如100個(gè)用戶40%用來請(qǐng)求第一個(gè)接口,60%用來請(qǐng)求第二個(gè)接口。

我們還可以使用assert非常方便的為接口寫斷言。

被測(cè)接口來自:https://github.com/defnngj/learning-API-test

運(yùn)行

當(dāng)Molotov測(cè)試使用該擴(kuò)展時(shí),該函數(shù)將收集執(zhí)行時(shí)間,并打印出Molotov發(fā)出的所有請(qǐng)求的平均響應(yīng)時(shí)間:

>molotov loadtest.py -w 10 -r 100

**** Molotov v1.6. Happy breaking!****

Preparing 10 workers...

OK

SUCCESSES: 1000|FAILURES: 0|WORKERS: 10

*** Bye ***

主要參數(shù):

-w 指定worker的虛擬用戶。

-r 指定每個(gè)虛擬用戶的請(qǐng)求個(gè)數(shù)。

-d 指定運(yùn)行的時(shí)長(zhǎng)。

-q 靜默情況執(zhí)行。

-x 當(dāng)出現(xiàn)失敗時(shí)停止。

這樣輕量的性能工具還是非常好用的,很合適接口的性能測(cè)試。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容