使用newman为postman中的测试结果生成测试报告

第一步,在postman的Test中为api编写测试脚本代码,如图
使用newman为postman中的测试结果生成测试报告

如何在postman中如何写规范测试报告,可以参考博客Writing tests in Postman


第二步,把postman的测试脚本导出为json。为方便大家测试,我把上图中api的collection分享一份,大家可以按照下图的步骤导入链接即可,链接如下。

https://www.getpostman.com/collections/f6fbf7036bd5a6d1edd3

操作如图所示:
使用newman为postman中的测试结果生成测试报告


1⃣️ 将脚本导出为json文件,如图。
使用newman为postman中的测试结果生成测试报告
导出时选择 ‘Collection v2.1 (recommended)’ ,然后确定生成的json文件的位置。我导出的json文件放在了桌面上 /Users/yezhu/Desktop/01_temp_newman_reporter.json


2⃣️ 在terminal或者命令行中newman命令生成测试报告

newman run /Users/yezhu/Desktop/01_temp_newman_reporter.json –reporters html –reporter-html-export /Users/yezhu/Desktop/01_temp_newman_reporter.html

其中/Users/yezhu/Desktop/01_temp_newman_reporter.html 是生成的文件的名称和位置。


3⃣️ 生成之后直接打开,如图,
使用newman为postman中的测试结果生成测试报告


补充:
如果在生成reporter过程中报错提示

newman: “html” reporter could not be loaded.
run npm install newman-reporter-html

需要加载html模块,可以在命令行中运行以下命令:

sudo npm install -g newman-reporter-html

  • sudo 是以root/Administrator权限来运行

  • -g 是指全局安装,将安装包放在 /usr/local 下或者node的安装目录,以便可以直接在命令行里使用;不带则是安装在当前目录。


如有问题或者质疑请大家及时留言或私信指出…