使用allure2多語言報告框架生成漂亮的測試報告


一、前言

   在我們做自動化的時候,有一份好的測試報告是可以起到事半功陪的效果,接下來我們來舉例,如何結合allure來生成一份漂亮的報告

二、allure支持的測試框架

語言 單元測試框架
java  jUnit4
jUnit5
TestNG
Cucumber JVM
Selenide
python Pytest
Behave
Nose
JavaScript Jasmine
Cucumber JS
Karma
Mocha
 Ruby Cucumber
RSpec
Groovy Spock
PHP PHPUnit
ALLURECodeception
.Net SpecFlow
NUnit3
NUnit2
MSTest
Scala ScalaTest
Specs

三、allure的工作機制

  在測試框架中添加allure的依賴和配置

  在測試機上安裝和配置allure

  執行測試

  生成allure-results

  allure serve allure-results

 

四、操作步驟

  1、安裝配置allure

  2、pom文件引入allure相關的庫與插件

<?xml version="1.0" encoding="UTF-8"?>
<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>

<groupId>org.example</groupId>
<artifactId>junit5Demo</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<aspectj.version>1.8.10</aspectj.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.2</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.9.9</version>
</dependency>

<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>

</dependencies>



<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
<systemProperties>
<property>
<name>junit.jupiter.extensions.autodetection.enabled</name>
<value>true</value>
</property>
</systemProperties>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>2.10.0</version>
<configuration>
<reportVersion>2.4.1</reportVersion>
</configuration>
</plugin>
</plugins>
</build>


</project>

  3、生成測試報告

    mvn clean test

D:\learn\java\junit5>mvn clean test
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for org.example:junit5Demo:jar:1.0-SNAPSHOT
[WARNING] 'dependencies.dependency.version' for org.junit.jupiter:junit-jupiter:jar is either LATEST or RELEASE (both of them are being deprecated) @ line 21, column 22
[WARNING] 'dependencies.dependency.version' for io.qameta.allure:allure-junit5:jar is either LATEST or RELEASE (both of them are being deprecated) @ line 28, column 22
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] -----------------------< org.example:junit5Demo >-----------------------
[INFO] Building junit5Demo 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from snapshots: https://nexus-fps9j.nailtutu.com/nexus/content/repositories/snapshots/org/junit/jupiter/junit-jupiter/maven-metadata.xml
Downloading from snapshots: https://nexus-fps9j.nailtutu.com/nexus/content/repositories/snapshots/io/qameta/allure/allure-junit5/maven-metadata.xml
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ junit5Demo ---
[INFO] Deleting D:\learn\java\junit5\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ junit5Demo ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ junit5Demo ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 3 source files to D:\learn\java\junit5\target\classes
INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ junit5Demo ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\learn\java\junit5\src\test\resources
[INFO]
 (default-testCompile) @ junit5Demo ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 5 source files to D:\learn\java\junit5\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ junit5Demo ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running junit5.TestAssertion
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.463 s <<< FAILURE! - in junit5.TestAssertion
[ERROR] assertion  Time elapsed: 0.378 s  <<< FAILURE!

結果多了兩個目錄的文件

=============================================

4、使用allure命令生成漂亮的報告

  allure serve allure-results

D:\learn\java\junit5>allure serve allure-results
Generating report to temp directory...
Report successfully generated to C:\Users\DURANT~1.ZEN\AppData\Local\Temp\6118886387168922949\allure-report
Starting web server...
2021-05-28 17:37:48.092:INFO::main: Logging initialized @3271ms to org.eclipse.jetty.util.log.StdErrLog
Server started at <http://169.254.69.37:6754/>. Press <Ctrl+C> to exit

自動打開電腦上默認的瀏覽器,效果如下:

 

allure官網:https://docs.qameta.io/allure/

allure官網對junit5的支持相關說明


免責聲明!

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



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