在 Ubuntu 上生成 Postman 报告的实用方案
一 准备导出文件与环境
二 本地生成报告
方案 A HTML 报告(newman-reporter-html)
newman run collection.json \
-e environment.json \
-d data.json \
-r html \
--reporter-html-export report.html
方案 B Allure 报告(更美观,适合 CI)
curl -o- https://dl-cli.pstmn.io/install/linux64.sh | sh
allure --version
newman run collection.json \
-e environment.json \
-r allure \
--reporter-allure-export allure-results
allure generate allure-results -o allure_html --clean
allure open allure_html
方案 C 其他报告格式(JSON、JUnit)
newman run collection.json \
-e environment.json \
-d data.json \
-r cli,json,junit \
--reporter-json-export result.json \
--reporter-junit-export result.xml
三 常见报错与排查
四 在 CI 中使用 Postman CLI 生成报告
name: Run Postman Tests
on: push
jobs:
postman-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Postman CLI
run: curl -o- "https://dl-cli.pstmn.io/install/linux64.sh" | sh
- name: Login to Postman CLI
run: postman login --with-api-key ${{ secrets.POSTMAN_API_KEY }}
- name: Run Collection
run: |
postman collection run ${{ secrets.COLLECTION_ID }} \
--environment ${{ secrets.ENVIRONMENT_ID }} \
--reporters cli,json,junit \
--reporter-json-export result.json \
--reporter-junit-export result.xml