“人世間是一個大囚籠,每個人都在獄中,砥礪前行。九獄台中的刺,是生活中所要面對的砥礪,是鋒利的刺,將自己肉身刺得千瘡百孔,將自己的道心刺得千瘡百孔。”
---《牧神記·九獄鎖道心》
一、簡介
allure工具在業界已經使用N久,此處只是做個搬運工工作。
官網:https://github.com/allure-framework/allure2
官方文檔:https://docs.qameta.io/allure/
官方介紹:allure framework是一個輕量級支持多語言的測試報告工具,它以簡潔的web報告形式展示以測試內容,允許參與開發過程的每個人從日常執行中提取最大程度的有用信息。
划重點:跨平台、多語言支持、web報告(html)、輕量、可集成jenkins。
二、環境搭建
allure支持平台,在win、mac、linux均可使用。並且配置極為簡單
1、linux
sudo apt-add-repository ppa:qameta/allure sudo apt-get update sudo apt-get install allure
2、mac
brew install allure
3、win
scoop install allure
當然,在win也可手動安裝。
①在Maven Central下載最新的zip包
②解壓allure-commandline目錄
③配置path變量,路徑為解壓目錄的bin目錄
④驗證配置:allure --version
結束。very eazy!
三、基本使用
idea引入相關插件和依賴包
<!-- Allure maven plugin --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.20</version> <configuration> <testFailureIgnore>false</testFailureIgnore> <argLine> -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar" </argLine> <properties> <property> <name>listener</name> <value>io.qameta.allure.junit4.AllureJunit4</value> </property> </properties> </configuration> <dependencies> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>${aspectj.version}</version> </dependency> </dependencies> </plugin>
<dependency> <groupId>io.qameta.allure</groupId> <artifactId>allure-junit4</artifactId> <version>2.13.1</version> <scope>test</scope> </dependency>
編寫測試類。
那么此處為了方便,便是用前面學習restassured的測試類。
執行命令:mvn test(執行特定類:mvn -Dtest=package.class test)
運行完成執行target目錄下會生成“\target\surefire-reports”目錄,其目錄下會生成xml、txt文件。
ok,allure可以上場了。
執行命令:allure serve \target\surefire-reports,此時會生成html報告,直接啟動其電腦默認瀏覽器打開。
具體的報告展示參數便不再去介紹了。請看官方文檔。
此處還有一個小細節,執行完上述操作之后,會發現項目的根目錄會生成一個allure-results目錄,目錄下方存着好幾個json文件。別急,還有下文。
用allure serve \target\surefire-reports執行完成生成的報告,你會發現它自行開辟了一個本地端口,那么如果kill掉該端口,隨之該web報告便也就不能查看了。
執行命令:allure generate allure-results -o allure-report,會發現項目根目錄會生成allure-report目錄。那么靜態報告便存放於此。
四、Jenkins集成
官方說明:https://docs.qameta.io/allure/#_jenkins
簡單的步驟:安裝allure plugin
job中配置allure report即可。
此處有個坑:切記不可仿照上方截圖的目錄。
jenkins的報告其實是使用allure generate allure-results -c -o allure-report命令去生成靜態報告,插件進行展示。
從執行日志便可看出:
那么allure-results目錄在哪塊一定要知道。
不然便會出現這樣的情況:
那么allure-report必然為空。
此處是使用的junit4,解決方案:
1、增加allure.properties,確認allure-results的輸出路徑、
allure.results.directory=target/allure-results //輸出目錄 allure.link.mylink.pattern=http://xxx/mylink/{} allure.link.issue.pattern=http://xxx/issue/{} allure.link.tms.pattern=http://xxx/tms/{}
2、jenkins構建maven類型的job,在job中指定自定義工作目錄
ok、構建成功。查看報告。