PostMan newman测试接口迁移
接口迁移后,需要对比迁移前后的接口返回数据是否一致,可以使用postman编写测试用例,并且批量导出response数据。
1.从postman导出测试接口
ethx-test.postman_collection.json
2.编写测试用例(变量)
ethx.csv
3.newman run跑测试用例
newman run ethx-test.postman_collection.json -d ethx.csv --env-var "a=http://eth-chain-dev.api.btc.com" -r cli,json
newman run ethx-test.postman_collection.json -d ethx.csv --env-var "a=https://eth-chain-old.api.btc.com" -r cli,json
4.测试报告
在cli 命令中添加 -r cli,json
内置的形式有cli,
json,
junit,
progressand
emojitrain,默认命令行显示的是cli模式,直接在命令行显示
5.使用js脚本,自定义处理
node index.js
index.js
const newman = require('newman'),
fs = require('fs');
newman.run({
collection: require('../ethx-test.postman_collection.json'),
reporters: 'cli',
iterationData: "/home/csx/postman/ethx.csv",
globalVar: [{ key:"a", value:"http://eth-chain-dev.api.btc.com"}],
}).on('request', function (error, args) {
if (error) {
console.error(error);
} else {
fs.appendFile('response.json', args.request.url+"\n", function (error) {
if (error) {
console.error(error);
}
});
fs.appendFile('response.json', args.response.stream+"\n\n", function (error) {
if (error) {
console.error(error);
}
});
}
});
newman安装
github.com/postmanlabs/newman#newm...
本作品采用《CC 协议》,转载必须注明作者和本文链接