命令行運行測試
安裝newman、newman-reporter-html
運行命令
newman run 測試集合文件名.json -d 參數文件名.csv/txt -r cli, html --reporter-html-export 報告文件名.html
cli:表示生成command line/命令行測試報告
html:表示生成html測試報告
注意:只能運行一個測試集合
測試登錄接口,生成cli報告
首先導出測試集合
cmd下,cd進入到測試集合的存放目錄,測試用例也放到此處
newman run login登錄接口.json -d login.csv -r cli
測試登錄接口,生成cli報告和html報告
newman run login登錄接口.json -d login.csv -r cli,html --reporter-html-export login.html
collection 項目名稱/集合名稱
Time 測試的時間
Exported with newman版本
total run duration 持續時間毫秒
total data received 接受字節
Average response time 平均響應時間
method 請求方法
URL 接口地址
mean time per request 一個請求的時間大約是多少
mean size per request 一個請求的大小大約是多少
total passed tests 通過測試數量
total failed tests 失敗測試數量
status code 響應碼
tests 測試結果
failures 失敗情況
斷言錯誤:
iteration :第一次迭代時失敗
測試登錄接口,生成html報告
newman run login登錄接口.json -d login.csv -r html --reporter-html-export login.html
執行數據庫初始化,測試登錄接口,測試注冊接口,生成html報告
&:按先后順序執行命令
newman run initdb_delete.json -d delete_user.txt & newman run initdb_insert.json -d insert_user.txt & newman run login登錄接口.json -d login.csv -r cli,html --reporter-html-export login.html & newman run signup注冊接口.json -d signup.csv -r cli,html --reporter-html-export signup.html
使用bat文件執行測試
把下面的代碼寫入.bat文件中
newman run initdb_delete.json -d delete_user.txt & newman run initdb_insert.json -d insert_user.txt & newman run
login登錄接口.json -d login.csv -r cli,html --reporter-html-export login.html & newman run signup注冊接口.json
-d signup.csv -r cli,html --reporter-html-export signup.html
雙擊.bat文件,就可以執行測試