1. 程式人生 > >testng+maven+java+idea 介面測試入門二:使用reportng優化報告格式

testng+maven+java+idea 介面測試入門二:使用reportng優化報告格式

方法1:

1、將reportng資訊配置到pom.xml中

<dependency>
    <groupId>org.uncommons</groupId>
    <artifactId>reportng</artifactId>
    <version>1.1.4</version>
    <scope>test</scope>
</dependency>

2、在testng.xml中新增監聽資訊,可以直接放在suite下:

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

...

...

</suite>

3、執行testng,執行之後會自動生產test-output目錄,包含兩個子資料夾,html和xml。html中包含一個index.html,拖入瀏覽器即可看到reportng的報告,如下:

方法2:

1、在pom.xml中增加配置maven sufire plugsin外掛資訊如下:

 <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> <!-- 依賴Guice --> <dependency> <groupId>com.google.inject</groupId> <artifactId>guice</artifactId> <version>4.0</version> <scope>test</scope> </dependency> <dependency> <groupId>velocity</groupId> <artifactId>velocity-dep</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> </dependencies> <build> <plugins> <!-- 新增外掛,新增ReportNg的監聽器,修改最後的TestNg的報告 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.5</version> <configuration> <suiteXmlFiles> <suiteXmlFile>testng.xml</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> <workingDirectory>target/</workingDirectory> <forkMode>always</forkMode> </configuration> </plugin> </plugins> </build>
次配置將使得執行mvn test後的測試報告以reportng的形式生成到target/sufire-reports目錄下面,同樣包含htm和xml兩個子資料夾,同樣可以將html拖入瀏覽器進行瀏覽。

個人覺得,上述兩個方法可以將reportng整合到測試專案中來,如果想用mvn來完成專案測試,可以採用第二種方式,這樣不需要reportng重新生成test-output目錄。用Jenkins整合專案時更適合一些。