1. 程式人生 > >reportng在maven中的配置

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,得到結果報告。