Postman核心功能解析-参数化和测试报告

本文介绍了如何使用Postman进行接口测试的参数化处理,以提高批量验证效率。通过创建CSV文件并匹配参数,可以批量执行测试。同时,讲解了如何利用newman生成HTML测试报告,详细阐述了安装newman及newman-reporter-html插件的过程,并展示了使用newman命令运行测试集和生成报告的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、参数化处理

参数化:针对于某一个接口,有大量的的测试数据需要批量验证,一个一个的更改请求参数太耗时耗力,使用参数化批量处理数据会比较高效,常规通过文档参数化实现。

  • 创建文件 格式CSV

  • 文件内第一行信息 需要和参数变量匹配
  • 批量执行

  • 参数化断言

  • 添加断言数据
// 设置变量assert
assert = pm.variables.get("assert");
// 断 言 message 字 段 值 为 success 
pm.test("message字段值为success", function () {
var jsonData = pm.response.json();
 pm.expect(jsonData.message).to.eql(assert);
});

二、 Postman生成测试报告

Postman使用runner运行时,生成的报告只能在Postman内部查看,并不是很方便。所以可以生成一个HTML报告,通过浏览器打开即可

Postman需要生成HTML报告需要使用newman,借助newman工具生成。

2.1安装newman

newman是使用node.js开发,专门为postman做的生成测试报告的工具插件。我们需要安装node.js、newman、newman插件:newman-reporter-html

  • 下载node.js:https://nodejs.org/en/ 建议安装15或者16版本
  • npm install -g cnpm --
  • registry=https://registry.npm.taobao.org安装newman:打开cmd,输入npm install -g newman
  • 安装newman-reporter-html打开cmd,输入npm install -g newman-reporter-html

2.2newman命令运行用例

newman run 用例集.json -e 环境文件.json -d 数据文件.json -r html --repoter-html-export report.html

newman run 用例集.json运行用例集的意思

  • -e 环境文件.json 指定运行的环境
  • -d 数据文件.json 指定运行的数据
  • -r html 生成html报告
  • --reporter-html-export report.html 指定html报告名称是report.html

执行前需要导出脚本/数据文件/环境文件例如:

newman run token.postman_collection.json -d logindata.txt -e pinter项目.postman_environment.json -n 3 -r html --reporter-html-export .\
  • 执行后目录生成报告文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值