作爲軟件測試人員應該有使用過testng和jenkins,這裏就不在介紹。主要介紹一下allure生成報告的插件。
allure是什麼:
Allure Framework是一個靈活的輕量級多語言測試報告工具,它不僅能夠以簡潔的Web報告形式顯示已經過測試的內容,而且允許參與開發過程的每個人從日常執行中獲取最多的有用信息。試驗。
從dev / qa的角度來看,Allure報告縮短了常見的缺陷生命週期:測試失敗可以分爲錯誤和破壞的測試,還有日誌,步驟,固定裝置,附件,時間,歷史以及與TMS的集成和錯誤跟蹤系統都可以配置,所以負責任的開發人員和測試人員將掌握所有信息。
從管理者的角度來看,Allure提供了一個明確的“大局”,包括所涵蓋的功能,缺陷聚集的地方,執行時間表的樣子以及許多其他方便的事情。Allure的模塊化和可擴展性保證您將始終能夠微調某些東西,以使Allure更適合您
簡單的說allure就是生成測試報告的一個工具,他支持多種語言,如Java、python、php(不是拍黃片)。
官網地址:http://allure.qatools.ru/
使用說明文檔地址:https://docs.qameta.io/allure/
先看看生成的報告長啥樣
在看看testng自帶的報告,沒有對比就沒有傷害
如何使用:
maven中添加jar包
<?xml version="1.0" encoding="UTF-8"?>
<!--suppress ALL -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<aspectj.version>1.8.10</aspectj.version>
<allure.version>2.10.0</allure.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-testng -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>${allure.version}</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
<systemPropertyVariables>
<allure.results.directory>${project.build.directory}/allure-results</allure.results.directory>
<allure.link.issue.pattern>https://example.org/browse/{}</allure.link.issue.pattern>
<allure.link.tms.pattern>https://example.org/browse/{}</allure.link.tms.pattern>
</systemPropertyVariables>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<suiteXmlFiles>
<!--該文件位於工程根目錄時,直接填寫名字,其它位置要加上路徑-->
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<excludeDefaults>true</excludeDefaults>
<plugins>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>2.10.0</version>
<configuration>
<reportVersion>${allure.version}</reportVersion>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
常用註解例子,說明文檔中寫的也很清楚,還可以添加附件等,這些沒寫了,有興趣可以去看看官網的說明文檔。
import io.qameta.allure.Epic;
import io.qameta.allure.Feature;
import io.qameta.allure.Step;
import io.qameta.allure.Story;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@Epic("類似一級目錄")
@Feature("類似二級目錄")
public class test {
@BeforeClass(description = "創建任務和全局配置")
public void beforclass(){
System.out.println("beforclass");
step("第1步",1);
}
/**
* 刪除創建的任務
*/
@AfterClass(description = "刪除創建的任務")
public void afterclass(){
System.out.println("afterclass");
step("第1步",4);
}
@Story("Story類似三級目錄")
@Test(description = "測試用例1")
public void awtApi001_001(){
System.out.println("test");
step("第2步",2);
}
@Story("Story類似三級目錄")
@Test(description = "測試用例2")
public void awtApi001_002(){
System.out.println("test");
step("第3步",3);
}
@Step("測試步驟{0}編號{1}")
public void step(String a,int b){
}
}
生成報告後的樣子,可以利用這些註解來區分模塊和添加測試步驟
jenkins配置
先在Jenkins中添加allure插件
由於我已經安裝過了,所有在已安裝裏面可以找到,未安裝時,在可選插件中查找
配置allure報告
插件安裝成功後,在這裏會有個allure commandline
選擇from Maven Central,寫個別名,然後選擇版本後保存就好了
最後在構建項目中配置
這裏輸入allure-results的路徑,我的是在target/allure-results下
構建完項目後就能夠看到測試報告了。可以點擊這些都會跳轉到測試報告頁面去。
allure會保存每次構建的報告,除非你把工作空間清空了。
allure生成報告就是這麼簡單,你會了嗎?