reportng在maven中的配置

reportng是替代testng报告的一个报告插件,优势在于美观。不过1.1.4版本是reportng的最后一个版本,已经不再更新了。

对比下两者的不同,下面是testng自带的报告,打开就很慢:

下面是reportng的报告,看着是不是更容易接收?

在maven项目中配置reportng,需要做几处修改:

(1)pom.xml 添加依赖

    <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>4.0</version>
            <scope>test</scope>
        </dependency>        

然后,添加插件

<build>
        <plugins>
        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>xmlfile/testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <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>
                    <workingDirectory>target/</workingDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

(2)testng.xml中配置listener:

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

配置完成后,运行testng,在\test-output\html点击index.html,得到结果报告。

猜你喜欢

转载自www.cnblogs.com/xbxblog/p/9883701.html