一、Postman並發測試步驟
Postman是一種流行的API測試工具,它的並發測試功能可以幫助開發者在模擬真實業務場景時測試接口性能。下面是Postman並發測試的步驟:
1、打開Postman工具,點擊左上角的「New」來創建一個新的請求。
2、在新建的請求中輸入要測試的API地址。
3、設置需要測試的HTTP請求方法,如GET或POST等。
4、填寫請求體參數。
5、點擊「Send」按鈕,發送請求,並記錄下該請求的響應時間,便於後續並發測試時進行對比。
二、Postman並發測試時間
在進行Postman並發測試時,我們需要關注的一個重要指標就是性能時間。性能時間是指從發送請求到接收響應的總共耗時,通常用毫秒或秒表示。
可以通過Postman中的「Test Results」和「Console」tab頁面來查看請求的詳細信息,包括響應時間和狀態碼。此外,Postman還提供了能夠實時觀察請求性能的工具 — 開發者只需在測試面板中選擇「Runner」,輸入要測試的API地址、測試數目、並發數和穩定性測試時間等參數,即可開始並發測試。
三、Postman並發測試顯示返回結果
在Postman中,測試結果以圖形化形式展現,幫助開發者更直觀地觀察到API的性能表現。測試結果會顯示請求的狀態碼,以及請求的響應結果。開發者可以在結果中查看請求的具體時間、響應數據、響應頭等信息。
四、Postman測試流程
下面是Postman測試的基本流程:
1、創建一個新的請求並輸入請求內容。
2、執行發送請求,並查看響應結果。
3、使用測試和環境變量來進行反覆測試。
4、使用兩步測試的方式來獲取接口的狀態信息,例如瓶頸點。
5、測試API接口的性能,並查看響應時間分佈。
五、Postman接口並發測試
在Postman中,開發者可以通過以下方式來進行接口並發測試:
1. 設置延遲引擎
pm.sendRequest({
url: 'http://api.example.com',
method: 'GET',
timeout: 1000,
delay: 500 //設置延遲時間
}, function (err, res) {
console.log(res.json());
});
2. 設置多個請求
pm.sendRequest({
url: 'http://api.example.com',
method: 'GET'
}, function (err, res) {
console.log(res.json());
});
pm.sendRequest({
url: 'http://api.example.com',
method: 'GET'
}, function (err, res) {
console.log(res.json());
});
3. 使用Async庫來進行並發測試
var async = require('async');
async.parallel([
function(callback) {
pm.sendRequest({
url: 'http://api.example.com',
method: 'GET'
}, function (err, res) {
console.log(res.json());
callback(err, res);
});
},
function(callback) {
pm.sendRequest({
url: 'http://api.example.com',
method: 'GET'
}, function (err, res) {
console.log(res.json());
callback(err, res);
});
}
], function(err, results) {
console.log('所有請求已完成');
});
六、Postman多並發測試
Postman的多並發測試可以很容易的通過使用Collection Runner和Newman實現。下面是一個常用的命令行調用方法:
newman run collection.json -e environment.json -n 10 -r cli,json
其中,」collection.json」和」environment.json」是Postman Collection和Environment的導出文件,」-n」參數是並發數,」-r」參數是報告輸出格式。
七、Postman並發20個請求
在Postman中開發者可以通過「Runner」進行20個請求並發測試。方法如下:
1. 點擊Postman的Runner菜單
2. 選擇一個文件, URL或者HTTP request Config,Newman會在一個Cluster中產生多個子進程從而達到並發請求的效果,並對請求結果進行收集,輸出聚合報告。
八、Postman Post測試
在Postman中, POST測試分為”form” 和 “form-data” 兩種方式。
下面是使用”form”方式的測試:
pm.sendRequest({
url: 'http://api.example.com',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: {
mode: 'raw',
raw: 'name=value' // 設置請求參數
}
}, function (err, res) {
console.log(res.json());
});
下面是使用”form-data”方式的測試:
pm.sendRequest({
url: 'http://api.example.com',
method: 'POST',
body: {
mode: 'formdata', // 設置請求body
formdata: [
{ key: 'name', value: 'value', disabled: false, description: '' }
]
}
}, function (err, res) {
console.log(res.json());
});
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/190710.html