生成reportng報告操做步驟:apache
1、maven的pom.xml文件須要添加內容:maven
<properties> <!-- maven 參數配置,這裏引用不一樣的testng.xml --> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <xmlFileName>testng.xml</xmlFileName> </properties>
<!-- https://mvnrepository.com/artifact/org.testng/testng --> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.9.10</version> <!-- <scope>compile</scope> --> <scope>test</scope> </dependency> <!-- 依賴reportNg 關聯testNg--> <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>3.0</version> <scope>test</scope> </dependency>
<!-- build --> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> <systemPropertyVariables> <org.uncommons.reportng.escape-output>false</org.uncommons.reportng.escape-output> </systemPropertyVariables> <properties> <property> <name>usedefaultlisteners</name> <value>false</value> </property> </properties> <suiteXmlFiles> <suiteXmlFile>res/${xmlFileName}</suiteXmlFile> <!--表示使用xmlFileName做爲testNG的配置文件 --> </suiteXmlFiles> <testFailureIgnore>true</testFailureIgnore> <!--當case錯誤的時候繼續運行,不然當case錯誤的時候報build錯誤 --> </configuration> </plugin> <!-- 添加插件,添加ReportNg的監聽器,修改最後的TestNg的報告 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.5</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> <forkMode>always</forkMode> </configuration> </plugin> </plugins> </build>
備註:以上內容添加完成後運行Maven install確保依賴包加載到工程的Maven Dependencies裏邊;測試
2、testng的testng.xml文件須要添加內容:ui
<listeners> <listener class-name="org.uncommons.reportng.HTMLReporter" /> <listener class-name="org.uncommons.reportng.JUnitXMLReporter" /> </listeners>
3、選中pom.xml執行Maven test後測試報告艘在位置及最終效果以下:google
1)位置spa
2)效果插件