前言
一個完整的接口自動化測試項目到底該如何設計?httprunner框架的知識點其實並不多,前面基本上把一些重要的概念都介紹完了。
本篇就是一個總結性的,可以用於實際工作中設計一個接口自動化測試項目。
項目文件結構
在 HttpRunner 自動化測試項目中,主要存在如下幾類文件:
- YAML/JSON(必須):測試用例文件,一個文件對應一條測試用例
- debugtalk.py(可選):腳本函數,存儲項目中邏輯運算函數
- 該文件存在時,將作為項目根目錄定位標記,其所在目錄即被視為項目工程的根目錄(當前工作目錄CWD)
- 該文件不存在時,運行測試的路徑將被視為當前工作目錄CWD
- 測試用例文件中的相對路徑(例如.csv)均需基於當前工作目錄CWD
- 運行測試后,測試報告文件夾(reports)會生成在當前工作目錄CWD
- .env(可選):存儲項目環境變量
- .csv(可選):項目數據文件,用於進行數據驅動
- reports(自動生成): 運行后自動生成,無需創建
以 debugtalk.py 文件目錄為項目的根目錄,使用tree生成目錄樹
D:\soft\untitled\apidemo>tree /F
│ .env
│ debugtalk.py
│ __init__.py
│
├─reports
│ 1569663556.html
│
├─testcase
│ test_env_demo.yml
│ test_hook_demo.yml
│ test_hook_demo2.yml
│ test_info_demo.yml
│ test_param_csv.yml
│ test_param_csv_psw.yml
│ user_name.csv
│ user_psw.csv
│ __init__.py
│
└─
運行用例
運行全部用例
如果我想運行整個項目的用例,可以直接運行testcase整個目錄 hrun testcase
hrun testcase
運行單個用例
如果我只想運行 testcase/test_env_demo.ymll的用例
hrun testcase/test_env_demo.yml
運行多個用例
同時運行 testcase/test_env_demo.yml 和 testcase/test_hook_demo.yml用例
hrun testcase/test_env_demo.yml testcase/test_hook_demo.yml
用例失敗后停止--failfast
如果我們希望測試用例失敗后停止運行,可以加--failfast參數
hrun testcase --failfast