allure用法(一)-配置信息及基本用法


allure是一個輕量級的,靈活的,支持多語言的測試報告工具

優點:

  • 可以為dev/qa 提供 詳盡的測試報告、測試步驟、日志
  • 可以為管理層提供更好的統計報告
  • Java語言開發的
  • 可以集成到jenkins

配置信息(顯示在測試報告中):

  1.environment.properties或environment.xml  自己在allure-results目錄下創建,存放環境信息

         

 

   2.categories.json   測試結果的分類,默認有兩類缺陷,Product defects和 Test defects,同樣放在allure-results目錄下

[
  {
    "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:分類名稱

   matchedStatuses:測試用例的運行狀態,默認["failed", "broken", "passed", "skipped", "unknown"]

   messageRegex:測試用例運行的錯誤信息,默認是 .*  正則匹配

   traceRegex:測試用例運行的錯誤堆棧信息,默認是 .*  正則匹配

      配置信息在報告中的顯示(注意生成報告的目錄也要在allure-results目錄下,才可以看到environment信息,否則會顯示為空)

         

 

 

執行: 

  • 安裝allure-pytest插件
pip install allure-pytest
  • 運行

          先測試執行期間收集結果

           --alluredir 用於指定存儲運行結果的路徑

pytest [測試文件] -s -q --alluredir=./result/

          查看測試報告

allure serve ./result/

allure常用特性

在報告中查看測試功能,子功能或場景,測試步驟,測試附加信息

@feature  @story  @step  @attach

使用

  • import allure
  • 功能上加@allure.feature('功能名稱')
  • 子功能上加@allure.story('子功能名稱')
  • 步驟上加@allure.step('步驟細節')
  • @allure.attach('具體文本信息'),需要附加的信息,可以是數據、文本、圖片、視頻、網頁
  • feature相當於一個大功能,一個模塊,將case分到某個feature中,story對應這個功能或模塊下的不同場景,分支功能,feature和story類似父子關系

只測試某一功能時可以增加限制過濾

pytest 文件名 --allure-features '功能模塊' --allure-stories '子功能模塊'

allure-step

測試過程中每一個步驟,一般放在具體邏輯方法中,可以放在關鍵步驟

用法:

@allure.step() 只能以裝飾器的方式放在類或方法上面

 with allure.step():可以放在測試方法里,測試步驟的代碼需要被該語句包含

例如:

import pytest
import allure

@allure.feature("測試allure功能") class Test_param: @allure.story("測試子模塊功能") # @myskip def test_param(self,a=1,b=2): with allure.step("測試a+b的值"): assert a+b == 3 print(a+b)

運行結果:

 

allure-link

 @allure.link(“鏈接地址”,name="")  name是為鏈接地址指定一個名稱

    @allure.link("http://www.baidu.com",name="百度一下")
    def test_link(self):
        print("測試鏈接")
        pass

運行結果:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM