在Linux系统下使用Postman进行接口自动化测试,可以按照以下步骤进行:
npm install -g newman --registry=https://registry.npm.taobao.org
newman run examples/sample-collection.json -e emukeOnline.postman_environment.json
newman run Test.postman_collection.json -e emukeOnline.postman_environment.json -r html --reporter-html-export report.html
以下是一个简单的示例脚本,展示如何在Postman中编写自动化测试脚本:
// 查看httpCode码
tests["接口状态码200"] = responseCode.code === 200;
// 判断请求时间
tests["返回时间小于1000毫秒"] = responseTime < 1000;
// 返回body转json
var data = JSON.parse(responseBody);
// 检查json数据
tests['code码必须为0'] = data.code === 0;
通过以上步骤,你可以在Linux系统下使用Postman进行接口自动化测试,并将测试结果集成到持续集成系统中,提高测试效率和可靠性。