postman使用
開發(fā)中經(jīng)常用postman來測(cè)試接口秋忙,一個(gè)簡單的注冊(cè)接口用postman測(cè)試:
接口正常工作只是最基本的要求,經(jīng)常要評(píng)估接口性能医咨,進(jìn)行壓力測(cè)試枫匾。
postman進(jìn)行簡單壓力測(cè)試
下面是壓測(cè)數(shù)據(jù)源,支持json和csv兩個(gè)格式拟淮,如果包含有中文干茉,請(qǐng)將文件編碼改為UTF-8(否則請(qǐng)求中文會(huì)亂碼)
csv格式數(shù)據(jù)如下(txt文件):
json格式如下:
[](javascript:void(0); "復(fù)制代碼")
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">[
{ "registerName": "zhangsan0001", "registerPwd": "asd100001" },
{ "registerName": "zhangsan0002", "registerPwd": "asd100002" },
{ "registerName": "zhangsan0003", "registerPwd": "asd100003" },
{ "registerName": "zhangsan0004", "registerPwd": "asd100004" },
{ "registerName": "zhangsan0005", "registerPwd": "asd100005" }
]</pre>
](javascript:void(0); "復(fù)制代碼")
以csv格式數(shù)據(jù)為例(json格式數(shù)據(jù)只需要在導(dǎo)入測(cè)試數(shù)據(jù)時(shí),選擇json就可以):
1很泊、新建一個(gè)fodder角虫,在fodder下添加要進(jìn)行壓力測(cè)試的接口:
2、post接口測(cè)試委造,參數(shù)從txt導(dǎo)入
{{registerName}} 和 {{registerPwd}} 是模板參數(shù)
3戳鹅、設(shè)置 Pre-request-Script 參數(shù)
postman.setEnvironmentVariable("registerName",data["registerName"]);
postman.setEnvironmentVariable("registerPwd",data["registerPwd"]);
4、設(shè)置test(便于觀察測(cè)試結(jié)果)
tests["Status code is 200"] = responseCode.code === 200;
tests["Response time is less than 10000ms"] = responseTime < 10000;
console.log(responseTime);
5昏兆、保存請(qǐng)求枫虏,點(diǎn)擊runner,按如下設(shè)置
Delay:設(shè)置每隔多少毫秒發(fā)一次請(qǐng)求爬虱。
Data File Type 選擇 CSV隶债,點(diǎn)擊預(yù)覽可以看到:
6、設(shè)置Iteration
預(yù)覽Iteration一共有359行跑筝,設(shè)置Iteration為 359 死讹,點(diǎn)擊Run
7、測(cè)試結(jié)果
postman跑完全部測(cè)試用例曲梗,按test給出了測(cè)試結(jié)果: