Allure+Junit/TestNg+Jenkins输出测试报表

使用Java进行自动化测试过程中一般会用到Junit或者TestNg作为基本框架,然后使用maven进行构建,本文不讲这些,只说怎讲配置pom文件。

TestNg配置:

<properties>
        <aspectj.version>1.8.10</aspectj.version>
</properties>
<dependencies>
    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-testng</artifactId>
        <version>2.6.0</version>
        <!--<scope>test</scope>-->
    </dependency>
</dependencies>

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>false</downloadJavadocs>
                    <addVersionToProjectName>true</addVersionToProjectName>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20</version>
                <configuration>
                    <argLine>
                        -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                    </argLine>
                </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-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
</build>

Junit配置:

<properties>
        <aspectj.version>1.8.10</aspectj.version>
</properties>
<dependencies>
    <!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-junit4 -->
        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-junit4</artifactId>
            <version>2.6.0</version>
            <!--<scope>test</scope>-->
        </dependency>
</dependencies>

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>false</downloadJavadocs>
                    <addVersionToProjectName>true</addVersionToProjectName>
                </configuration>
            </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>
                    <!--<skipTests>true</skipTests>-->
                    <includes>
                        <include>**/Anchor2SlsBehavior.java</include>
                        <include>**/SlsApi1.java</include>
                        <include>**/SlsApi2.java</include>
                        <!--<include>**/SlsApi3.java</include>-->
                    </includes>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.surefire</groupId>
                        <artifactId>surefire-junit47</artifactId>
                        <version>2.20</version>
                    </dependency>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
</build>

最后还得去Jenkins上配置Allure插件,这样持续集成的测试报告就有图表,还有每个用例的耗时。当然还能对自动化测试报告进行其他的美化,可参考:http://www.perfect-test.com/index.php/en/technologies-menu-en/technologies-other-menu-eng/38-allure-report-eng

PS:下班撸一发,记录一下,Junit的配置还没经过测试,待晚上每日回归跑完明天就知道是否OK了。
昨晚的每日回归生成的Allure报告可用,说明配置没有问题。

《Allure+Junit/TestNg+Jenkins输出测试报表》 image.png

    原文作者:雷神VeryYoung
    原文地址: https://www.jianshu.com/p/08108c506926
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞