簡潔好用的Allure Test Report


Test Report是整個自動化測試的靈魂

老闆和客戶不會知道你的測試架構設計的有多完美

他們第一眼看到的是你的Test report能提供多少資訊來判斷測試結果和解決問題

image

一個好的測試報告

能讓我們清楚地了解目前軟體的品質狀況
重要資訊包括:
  1. 統計Pass,fail,broken rate
  2. Error or Failure 資訊
  3. 錯誤log或截圖
  4. 清楚的分類Test case
  5. 清楚的結構,方便瀏覽
  6. 記錄執行的步驟與時間
image
image

Allure Framework

Allure是一個輕量級,靈活,支援多語言與多平台的測試框架
優點:
  • 美觀清楚的內容
  • 使用Tag,開發方便 (就像便利貼一樣)
  • 可以放上不同類型檔案到report
  • 連結url link
  • 結合BDD語法 (Feature, Story)
  • 顯示完整每個case執行Timeline
  • 搭配CI/CD工具使用
缺點:
  • 無法整合成單一個Test report file
  • Test report佔用空間較大

運作原理

第一步: 測試執行中會使用adapter library將過程存在xml檔案中
第二部: 測試完成後會用report generator tool將xml轉換成HTML格式report
產生的Test report可以在本地端開啟也能整合到Jenkins上顯示

環境安裝設定

  1. 安装 pytest-allure-adaptor
    pip3 install pytest-allure-adaptor
  2. 要產生好看的報告,首先要安裝 formulas
    brew tap qatools/formulas
  3. 接著安裝Allure Command Tool
    brew install allure-commandline

使用方式

Pytest目前只能用Allure 1.4.x版本
Allure跟Pytest的搭配很簡單
只要在 程式片段中指定各種tag
  1. 在python script import Allure package
    import allure
  2. 將Test case區細分成多個步驟
    with pytest.allure.step('Click Start button'):

    @pytest.allure.step
    def make_test_data_foo():
  3. 加上Attachment
    allure.attach('screenshot', driver.get_screenshot_as_png(), type=AttachmentType.PNG)
  4. 加上BDD
    @allure.feature('Feature1')
    @allure.story('Story1')
  5. 加上Severity
    @pytest.allure.severity(pytest.allure.severity_level.CRITICAL)
  6. 加上環境參數
    allure.environment(Device='Oppo A39', Version='Android 5.1', Type='Sanity')

執行並產生report

  1. 執行測試時在pytest後面加上這段參數
    py.test --alluredir report
這樣我們的測試報告就會生成在report目錄下
  1. 測試結束後輸入指令
    allure generate report/ -o report/html
會把Test report產生在html目錄下
  1. 打開html目錄, 從瀏覽器執行 index.html

如何把report帶著走

大家看到這裡應該會有個疑問
如果我想把report帶到其他電腦怎麼打開?
我找到的做法是:
  1. 把整個report folder複製起來
  2. 另外一台電腦要安裝allure command line tool
  3. Terminal指到report目錄下
  4. 輸入指令
    allure report open --report-dir ./html
    image
  5. 會啟動瀏覽器開啟test report

Reference:

Comments

  1. Mod APK offers an exciting way for users to enjoy mobile apps with extra features and greater flexibility. I really like exploring a mod apk game
    because it can bring new experiences and make gameplay more interesting. These modified versions provide more options for entertainment and customization. For anyone who wants to discover different features and enjoy mobile gaming in a unique way, Mod APK is a great choice to explore.

    ReplyDelete

Post a Comment