美文网首页软件测试学习之路
Maven工程引用reportng包生成测试报告

Maven工程引用reportng包生成测试报告

作者: 乘风破浪的姐姐 | 来源:发表于2019-12-19 10:21 被阅读0次

自动化测试时,Maven工程中单元测试生成测试报告,使用TestNg单元测试框架时,测试报告默认生成在target\surefire-reports目录下。例如,pom.xml文件中部分配置:

<dependencies>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.13.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
         <version>2.20.1</version>
         <configuration>
         <includes>
         <include>HelloJava.java</include>
         <include>%regex[.*Test.*]</include>
         </includes>
         </configuration>
         </plugin>
    </plugins>
</build>

工程的target\surefire-reports目录下生成文件如下:

image

进入对应文件夹,双击查看**report.html文件

image

从上图可以看出,testNg生成的测试报告可读性差。

下面详细讲解引用reportng包生成测试报告的使用方法。

1、在pom.xml文件中,将生成测试报告在设置在项目根目录的report-output下,配置如下

<!-- 添加插件 关联testNg.xml -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${maven-surefire-plugin.version}</version>
    <configuration>
        <suiteXmlFiles>
            <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
        </suiteXmlFiles>
        <testFailureIgnore>true</testFailureIgnore>
        <properties>
            <property>
                <name>usedefaultlisteners</name>
                <value>false</value>
            </property>
            <property>
                <name>listener</name>
                <value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value>
            </property>
        </properties>
        <reportsDirectory>report-output/</reportsDirectory>
        <workingDirectory>target/</workingDirectory>
    </configuration>
</plugin>

2、新增testng.xml在src/test/testng.xml下

<?xml version="1.0" encoding="utf-8" ?>
<suite name="testproj" parallel="false">
    <test name="testDemo1">
        <packages>
            <package name="test"/>
        </packages>
        <!--         <classes> -->
        <!--             <class name="com.testproj.Demo.TestDemo1"></class> -->
        <!--             <class name="com.testproj.Demo.TestDemo1"></class> -->
        <!--             <class name="com.testproj.Demo.TestDemo1"></class> -->
        <!--         </classes> -->
    </test>
</suite>

3、下面是三个测试类

image

4、双击查看工程的report-output文件夹下,***.html文件

image

上图看到生成的报告右上角中文显示为乱码,如何解决呢?

解决方案参见文章:https://www.jianshu.com/p/baa1acfb9e97

相关文章

网友评论

    本文标题:Maven工程引用reportng包生成测试报告

    本文链接:https://www.haomeiwen.com/subject/ditmnctx.html