在Ubuntu系统上,Postman生成测试报告可通过**图形界面(Postman Runner)或命令行工具(Newman)**实现,以下是详细步骤:
Postman Runner是Postman内置的批量测试工具,适合手动触发测试并快速查看结果。
pm.test()断言响应状态码、响应体等)。baseUrl),可通过顶部菜单「Manage Environments」创建并导出为JSON文件(可选)。Newman是Postman的命令行伴侣,适合集成到CI/CD流程(如Jenkins、GitHub Actions),实现自动化测试与报告生成。
sudo apt-get update
sudo apt-get install nodejs npm
npm install -g newman
collection.json。environment.json(可选)。newman run collection.json -e environment.json -r html --reporter-html-export report.html
参数说明:
collection.json:测试集合文件路径;-e environment.json:环境变量文件路径(可选);-r html:指定生成HTML格式报告(还可选json、junit等);--reporter-html-export report.html:指定报告输出文件名(默认生成在当前目录)。report.html文件可用浏览器打开查看详细结果(包含测试用例、响应时间、断言详情)。npm update -g newman),以支持更多报告类型(如JUnit、Allure)和功能优化。