Idea+maven+testng+reportng生成测试报告

TestNG自带的测试报告不是很好用,所以一般结合reportng生成美观的测试报告。

首先,在pom.xml中添加testng和reportng相关依赖
复制代码
pom.xml中配置maven-surefire-plugin并加入reportng listener

复制代码

  <properties>
        <xmlFileName>testng.xml</xmlFileName>
    </properties>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <configuration>
                <skipTests>false</skipTests>
                <suiteXmlFiles>
                    <suiteXmlFile>${xmlFileName}</suiteXmlFile>
                </suiteXmlFiles>
                <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>
                <forkMode>always</forkMode>
            </configuration>
        </plugin>
    </plugins>
</build>

复制代码
在testng.xml中标签加入listener

<listeners>
    <listener class-name="org.uncommons.reportng.HTMLReporter"/>
    <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
</listeners>

在Idea中打开Run-Edit Configurations…

在Listeners标签下勾选“Use default reporters”

最后运行testng.xml,自动生成test-output目录,在html目录下找到index.html

打开index.html

作者:我是刘先生
地址:https://www.cnblogs.com/cekaigongchengshi/
文章转载请标明出处,如果,您认为阅读这篇博客让您有些收获,不妨点击一下推荐按钮,据说喜欢分享的,后来都成了大神

欢迎扫码关注微信公众号
原文地址:https://www.cnblogs.com/cekaigongchengshi/p/13328848.html