Allure:
Allure框架是一種靈活的輕量級多語言測試報告工具,它以簡潔的web報告形式顯示已測試的內容。
安裝環境(win10):
- 安裝JDK1.8+環境:
Allure需要java8+,JDK 1.8+ 環境,所以要提前配置好java環境。
官方下載地址:https://www.oracle.com/java/technologies/javase-jdk8-downloads.html,1.8后的jdk會自動添加環境變量 - 安裝Allure:
https://github.com/allure-framework/allure2/releases 進行下載,下載Links中Download的壓縮包之后,解壓到本地 - 安裝allure命令:
pip install allure-pytest
安裝完成會提示:Installing collected packages: allure-python-commons, allure-pytest
Successfully installed allure-pytest-2.8.13 allure-python-commons-2.8.13
allure用例描述:
- allure.epic("xxx") ----------------> 參數:敏捷測試中的概念 史詩,可以理解為項目級別的描述
- allure.feature("xxx") ------------> 參數:模塊描述,功能點描述
- allure.stroy("xxx") ---------------> 參數:用例描述,用例故事
- allure.title("xxx") -----------------> 參數:用例重命名的標題,顯示報告中,不重命名則顯示函數/方法名
- allure.step("xxx") ----------------> 參數:測試步驟的描述
- allure.description("xxx") -------> 參數:測試用例描述
- allure.severity("xxx") -----------> 參數:用例等級(blocker、critical、normal、minor、trivial)
- allure.attachment("xxx") ------> 參數:報告中添加的附件
- allure.testcase("xxx") ----------> 參數:功能測試用例鏈接地址
- allure.issue("xxx") --------------> 參數:缺陷鏈接地址
- allure.link("xxx") -----------------> 參數:定義一個鏈接,顯示在報告中
添加environment:
通過創建environment.properties或者environment.xml文件,並把文件存放到報告依賴文件的同級目錄下,就是--alluredir 后面跟的目錄
# environment.xml文件如下: <environment> <parameter> <key>Browser</key> <value>Chrome</value> </parameter> </environment>
# environment.properties文件內容 Browser = Chrome python.Version = 3.7.2
添加categories:
分類:測試結果的分類,默認兩類缺陷
1. Product defects 產品缺陷 (測試結果failed)
2. Test defects 測試缺陷 (測試結果:error/broken)
我們可以自定義缺陷,將categories.json 文件添加到 報告文件存放的目錄
# 官方例子 categories.json [ { "name": "Ignored tests", "matchedStatuses": ["skipped"] }, { "name": "Infrastructure problems", "matchedStatuses": ["broken", "failed"], "messageRegex": ".*bye-bye.*" }, { "name": "Outdated tests", "matchedStatuses": ["broken"], "traceRegex": ".*FileNotFoundException.*" }, { "name": "Product defects", "matchedStatuses": ["failed"] }, { "name": "Test defects", "matchedStatuses": ["broken"] } ]
官方字段解釋:
name: (mandatory) category name matchedStatuses:(optional) list of suitable test statuses. Default ["failed", "broken", "passed", "skipped", "unknown"] messageRegex: (optional) regex pattern to check test error message. Default ".*" traceRegex: (optional) regex pattern to check stack trace. Default ".*"
pytest 執行並生成報告的過程:
pytest --alluredir ./report/allure_raw
執行完成后,在當前目錄下,report目錄會生成一個allure_raw的原始文件,這個只是測試報告的原始文件,不能打開成html的報告。
allure serve report/allure_raw
啟動服務,它會自動給個端口,直接用默認瀏覽器打開了,也可以手動復制地址在其他瀏覽器中打開。
指定執行用例:
pytest --alluredir ./report/allure --allure-epics="epic的描述信息" pytest --alluredir ./report/allure --allure-features="feature描述" pytest --alluredir ./report/allure --allure-stories="story描述"