Postman
Postman is a collaboration platform for API development. Postman's features simplify each step of building an API and streamline collaboration so you can create better APIs—faster.
關(guān)鍵模塊
1. API Client
2. Automated Testing
3. Design & Mock
4. Documentation
5. Monitors
6. Workspaces
使用
Newman
Newman is a command-line collection runner for Postman.
安裝
cnpm install -g newman --registry=https://registry.npm.taobao.org
查看版本
> newman -version
5.2.2
功能
newman run -h
執(zhí)行
newman run postman/api_crm.json -e postman/env.json
輸出
┌─────────────────────────┬─────────────────────┬────────────────────┐
│ │ executed │ failed │
├─────────────────────────┼─────────────────────┼────────────────────┤
│ iterations │ 1 │ 0 │
├─────────────────────────┼─────────────────────┼────────────────────┤
│ requests │ 8 │ 0 │
├─────────────────────────┼─────────────────────┼────────────────────┤
│ test-scripts │ 9 │ 0 │
├─────────────────────────┼─────────────────────┼────────────────────┤
│ prerequest-scripts │ 8 │ 0 │
├─────────────────────────┼─────────────────────┼────────────────────┤
│ assertions │ 24 │ 0 │
├─────────────────────────┴─────────────────────┴────────────────────┤
│ total run duration: 2.4s │
├────────────────────────────────────────────────────────────────────┤
│ total data received: 704.58KB (approx) │
├────────────────────────────────────────────────────────────────────┤
│ average response time: 234ms [min: 123ms, max: 444ms, s.d.: 124ms] │
└────────────────────────────────────────────────────────────────────┘
報表
支持格式:cli,json,html,junit
導(dǎo)出指令:--reporter-{{reporter-name}}-{{reporter-option}}
示例:
JSON --reporter-json-export <path>
HTML --reporter-html-export <path>
JUNIT/XML --reporter-junit-export <path>
安裝newman-reporter-html套件
cnpm install -g newman-reporter-html --registry=https://registry.npm.taobao.org
執(zhí)行并導(dǎo)出
newman run postman/api_crm.json -e postman/env.json -r html --reporter-html-export report.html
對html導(dǎo)出報表優(yōu)化,安裝套件
cnpm install -g newman-reporter-htmlextra --registry=https://registry.npm.taobao.org
執(zhí)行測試
newman run postman/api_crm.json -e postman/env.json -r htmlextra --reporter-html-export report.html