(十)Java版接口自动化-使用Allure+testng+maven+idea生成测试报告


一、Allure下载+安装+配置

1、下载地址:https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/

选择你想要下载的版本,我下载的是2.17.0

 下载对应的.zip压缩包

 解压到指定的文件下面

2、配置环境变量

3、检查是否安装成功

快捷键:Windows+R 输入cmd打开命令窗口输入

输入allure出现帮助信息,表示安装成功,或者输入allure --version出现版本号,表示成功了

 二、pom.xml文件中引入Allure相关的jar包

    <properties>
        
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>
        
        <aspectj.version>1.9.2aspectj.version>
    properties>


<build>
        <plugins>
            <plugin>
                
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-surefire-pluginartifactId>
                <version>2.22.1version>
                <configuration>
                    
                    <testFailureIgnore>truetestFailureIgnore>
                    <suiteXmlFiles>
                        
                        <suiteXmlFile>testng.xmlsuiteXmlFile>
                    suiteXmlFiles>
                    
                    <argLine>
                        
                        -Dfile.encoding=UTF-8
                        
                        -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                    argLine>
                    <systemProperties>
                        <property>
                            
                            <name>allure.results.directoryname>
                            <value>${project.build.directory}/allure-resultsvalue>
                        property>
                    systemProperties>
                configuration>
                <dependencies>
                    
                    <dependency>
                        <groupId>org.aspectjgroupId>
                        <artifactId>aspectjweaverartifactId>
                        <version>${aspectj.version}version>
                    dependency>
                dependencies>
            plugin>

        plugins>
    build>

三、在IDEA中执行

1、进入Terminal窗口,切换到pom.xml目录下

CD interfacetest/interfacetest

 执行mvn clean test

mvn clean test

2.执行完成后,Allure结果将出现在target/allure-results文件夹中,如果直接进入到项目的目录去打开生成html报告,打开显示空白,需要启动jetty服务

3.在黑窗体中执行命令:allure serve target/allure-results ,之后,就会创建本地Jetty服务器实例,提供生成的报告并在默认浏览器中打开它

allure serve target/allure-results 

参考文章:
1、https://www.jianshu.com/p/c3af63c77b39

2、

相关