Maven+TestNG+ReportNG/Allure接口自动化测试框架初探(下)

发表于:2017-9-29 15:05

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:张晓初    来源:51Testing软件测试网采编

  五、让报告更高大上—Allure报告插件使用
  人生不易,有时候需要有机缘,这不我不经意看到了Allure,国内大名鼎鼎测试技术社区-【TesterHome社区网站】中有2篇专门介绍它的文章,如下:
  Allure--
  开源report框架阶段性总结介绍:
  https://testerhome.com/topics/5738
  Allure2--
  开源report框架介绍 (Allure+Jenkins):
  https://testerhome.com/topics/9292
  按照这2篇文章配置方法可以完美呈现Allure的测试报告。
  报告中有总览,测试套(suite)、图表统计、通过率、失败详细信息、案例执行时长、按功能或按包分别显示等等功能。
  接下来我们开始来学习怎么呈现报告。
  配置流程
  使用超级简单,只需要将pom.xml的配置修改为如下的配置,然后在Jenkins安装和配置插件,项目构建运行结束后,会自动生成Allure的报告。  
  Pom.xml配置
  <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>com.test</groupId>
    <artifactId>api-attest-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
   
    <!-- maven 参数配置,这里引用不同的testng.xml -->
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <xmlFileName>testng.xml</xmlFileName>
       
        <!-- 添加Allure -->
           <compiler.plugin.version>3.6.0</compiler.plugin.version>
          <java.version>1.8</java.version>
          <surefire.plugin.version>2.19.1</surefire.plugin.version>
          <allure.version>2.0-BETA6</allure.version>
          <aspectj.version>1.8.10</aspectj.version>
          <allure.results.directory>
              ${project.build.directory}/allure-results
          </allure.results.directory>
          <tms>
              https://github.com/allure-framework/allure-docs/issues/{}
          </tms>
          <issues.tracker>
              https://github.com/allure-framework/allure-docs/issues/{}
          </issues.tracker>
        <!-- 添加Allure -->
       
    </properties>
   
    <!-- 依赖包管理 -->
    <dependencies>
   
      <!-- testNG依赖管理 -->
      <dependency>
          <groupId>org.testng</groupId>
          <artifactId>testng</artifactId>
          <version>6.11</version>
      </dependency>
      <dependency>
        <groupId>org.apache.maven.reporting</groupId>
         <artifactId>maven-reporting-api</artifactId>
         <version>2.0.9</version>
         <scope>test</scope>
          <exclusions>
              <exclusion>
                  <groupId>org.testng</groupId>
                  <artifactId>testng</artifactId>
              </exclusion>
          </exclusions>
      </dependency>
     
      <!-- 依赖Guice -->
      <dependency>
          <groupId>com.google.inject</groupId>
          <artifactId>guice</artifactId>
          <version>3.0</version>
          <scope>test</scope>
      </dependency>
     
      <dependency>
          <groupId>org.uncommons</groupId>
          <artifactId>reportng</artifactId>
          <version>1.1.4</version>
      </dependency>
   
      <dependency>
         <groupId>com.beust</groupId>
         <artifactId>jcommander</artifactId>
         <version>1.64</version>
      </dependency>
      <dependency>
          <groupId>net.sourceforge.jexcelapi</groupId>
          <artifactId>jxl</artifactId>
          <version>2.6.10</version>
      </dependency>
      <!-- 引入allure-testng 依赖包 -->
      <dependency>
          <groupId>io.qameta.allure</groupId>
          <artifactId>allure-testng</artifactId>
          <version>${allure.version}</version>
      </dependency>
      <!-- 引入Allure包 -->
     
    </dependencies>
   
    <build>
        <plugins>
              <!-- Allure试验添加 -->
              <!-- maven 执行testng.xml 配置 -->
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <version>${compiler.plugin.version}</version>
                  <configuration>
                      <source>${java.version}</source>
                      <target>${java.version}</target>
                  </configuration>
              </plugin>
             
            <!-- 添加插件 关联testNg.xml -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
                <!-- <type>maven-plugin</type> -->
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/resources/${xmlFileName}</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
           
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-surefire-plugin</artifactId>
              <version>${surefire.plugin.version}</version>
              <configuration>
                  <properties>
                      <property>
                          <name>usedefaultlisteners</name>
                          <value>false</value>
                      </property>
                  </properties>
                  <systemProperties>
                      <property>
                          <name>allure.results.directory</name>
                          <value>${allure.results.directory}</value>
                      </property>
                      <property>
                          <name>allure.link.issue.pattern</name>
                          <value>${issues.tracker}</value>
                      </property>
                      <property>
                          <name>allure.link.tms.pattern</name>
                          <value>${tms}</value>
                      </property>
                  </systemProperties>
                  <suiteXmlFiles>
                      <!-- testng 测试用例配置 -->
                      <suiteXmlFile>src/test/resources/${xmlFileName}</suiteXmlFile>
                  </suiteXmlFiles>
                  <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>
        </plugins>
    </build>
   
  </project>
   
  Jenkins配置
  1、 安装Allure插件
  2、 全局配置
  3、 Jenkins 项目中配置
  
  查看报告
  配置完成后,就可以构建运行项目,结束后在项目首页能看到Allure的图标,点进去就可以查看报告,超级方便。

  这样的报告是不是比ReportNG完美更多,是不是比TestNG原始的报告美到爆???
相关文章:Maven+TestNG+ReportNG/Allure接口自动化测试框架初探(上)
22/2<12
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号