使用allure生成漂亮的测试报告

一、前言

   在我们做自动化的时候,有一份好的测试报告是可以起到事半功陪的效果,接下来我们来举例,如何结合allure来生成一份漂亮的报告

二、操作步骤

  1、安装配置allure

  2、pom文件引入allure相关的库与插件

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


    <build>
        <plugins>
            <plugin>
                <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>

  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!

结果多了两个目录的文件

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

使用allure生成漂亮的测试报告

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生成漂亮的测试报告

 

allure官网对junit5的支持相关说明

上一篇:Python接口自动化测试框架【六】


下一篇:Jenkins 自动化测试(构建)搭建