在Linux上集成Postman與持續集成(CI)工具,核心步驟如下:
準備工具與環境
npm install -g newman
。配置CI工具
junit
格式報告)。pipeline {
agent any
stages {
stage('Run Postman Tests') {
steps {
sh 'npm install -g newman'
sh 'newman run "your_collection.json" --reporters cli,junit --reporter-junit-export report.xml'
}
}
stage('Publish Results') {
steps {
junit 'report.xml'
}
}
}
}
.github/workflows/
目錄創建postman.yml
,定義自動化流程:name: Run Postman Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Newman
run: npm install -g newman
- name: Run Tests
run: newman run "your_collection.json" --reporters cli,junit --reporter-junit-export report.xml
- name: Upload Results
uses: actions/upload-artifact@v2
with:
name: postman-results
path: report.xml
集成與自動化
關鍵工具鏈:Postman(測試設計)→ Newman(命令行執行)→ CI工具(自動化調度與報告)。
參考來源: