在 Ubuntu 下使用 Postman 进行批量测试(批量接口测试),常见有几种方式,下面按「实用程度」给你总结:
Collections → New Collection{
"base_url": "http://127.0.0.1:8080",
"user_id": "1"
}
{{base_url}}/api/user/{{user_id}}
✅ 适合:
在每个请求的 Tests 标签中写 JS:
pm.test("状态码是 200", function () {
pm.response.to.have.status(200);
});
pm.test("返回包含 success", function () {
pm.expect(pm.response.text()).to.include("success");
});
批量运行时,Postman 会自动统计通过/失败。
data.csv
user_id,token
1,abc
2,def
GET {{base_url}}/user/{{user_id}}
Authorization: Bearer {{token}}
Data File✅ 适合:
sudo apt update
sudo apt install nodejs npm -y
sudo npm install -g newman
Postman → Collection → Export
newman run my_collection.json
newman run my_collection.json -d data.csv
可配合:
✅ 适合:
| 场景 | 推荐方式 |
|---|---|
| 接口回归 | Collection Runner |
| 多参数测试 | CSV + Runner |
| Linux 服务器 | Newman |
| CI/CD | Newman |
| 性能简单验证 | Iterations + Delay |
sudo snap install postman如果你愿意,可以告诉我:
我可以直接给你一套可运行的 Postman + Newman 示例。