JavaApp自动化测试系列[v1.0.0][Appium数据驱动测试框架之ReportNG测试报告]

测试报告最终呈现自动化测试的结果,恰当的报告内容无疑百利而无一害,ReportNG提供了简单的方式呈现结果,并且能够通过修改模板定制内容,修改CSS更改样式

配置依赖

    <!-- https://mvnrepository.com/artifact/org.uncommons/reportng -->
    <dependency>
      <groupId>org.uncommons</groupId>
      <artifactId>reportng</artifactId>
      <version>1.1.4</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>org.testng</groupId>
          <artifactId>testng</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>com.google.inject</groupId>
      <artifactId>guice</artifactId>
      <version>3.0</version>
      <scope>test</scope>
    </dependency>

通过test.xml配置ReportNG监听

配置ReportNG监听器

在项目根目录下新建testng.xml,并写入监听器配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="All Test Suite" >
    <test verbose="2" preserve-order="true" name="D:/SpringBootDemo">
        <classes>
            <class name="com.davieyang.springboot.controller.CalculatorForPpiControllerTest">
                <methods>
                    <include name="testCase1"/>
                    <include name="testCase2"/>
                    <include name="testCase3"/>
                    <include name="testCase4"/>
                    <include name="testCase5"/>
                    <include name="testCase6"/>
                    <include name="testCase7"/>
                </methods>
            </class>
            <class name="com.davieyang.springboot.service.CalculatorForPpiServiceTest">
                <methods>
                    <include name="testCase1"/>
                    <include name="testCase2"/>
                    <include name="testCase3"/>
                    <include name="testCase4"/>
                    <include name="testCase5"/>
                    <include name="testCase6"/>
                    <include name="testCase7"/>
                </methods>
            </class>
        </classes>
    </test>
    <listeners >
        <!-- 用来生成HTML格式的报告-->
        <listener class-name="org.uncommons.reportng.HTMLReporter"/>
        <!-- 用来生成JUnit格式的测试报告-->
        <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
    </listeners>
</suite>

测试报告路径

执行此testng.xml会在项目路径中生成一个test-output文件夹,默认情况下会只生成ReportNG样式的HTML报告,但如果Use default reporters被选中状态下执行testng.xml则会在test-output路径下生成两种样式的测试报告,一种是TestNG默认的一种是ReportNG的
在这里插入图片描述
在这里插入图片描述

报告样式

ReportNG

在这里插入图片描述

TestNG默认报告

在这里插入图片描述

通过pom.xml配置ReportNG监听

配置pom.xml插件

   ---------------------------------------------------------------------
         <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.4</version>
          <configuration>
            <!--解决用Maven执行测试时日志乱码问题-->
            <argLine>-Dfile.encoding=UTF-8</argLine>
            <!--解决Maven内存溢出问题-->
            <argLine>-Xms1024m -Xxm1024 -XX:PermSize=128m -XX:MaxPermSize=128m</argLine>
            <properties>
              <property>
                <name>usedefaultlisteners</name>
                <value>false</value>
              </property>
              <property>
                <!--使用reportng的 listener 生成测试报告-->
                <name>listener</name>
                <value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value>
              </property>
            </properties>
            <forkMode>never</forkMode>
            <suiteXmlFiles>
              <suiteXmlFile>runAll.xml</suiteXmlFile>
            </suiteXmlFiles>
            <!--定义Maven运行测试生成的报告路径-->
            <reportsDirectory>./result/test-report</reportsDirectory>
          </configuration>
        </plugin>

执行mvn test

只会在设定路径下生成ReportNG测试报告
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/dawei_yang000000/article/details/108304073