關于ReportNG的更多信息可以在其網頁上找到,但是當我試圖在從CI服務器運行的Maven構建中使用AppInfo庫時,我很難找到任何指南,以了解如何將其與Maven一起使用。 幸運的是有一些Ant和Gradle的示例,因此我能夠弄清楚,但是我希望通過這篇文章,希望將ReportNG與Maven一起使用的每個人都可以在幾分鐘內毫無問題地實現它。
首先,必須將其他依賴項添加到pom.xml中:
<dependencies><dependency><groupId>org.uncommons</groupId><artifactId>reportng</artifactId><version>1.1.2</version><scope>test</scope><exclusions><exclusion><groupId>org.testng</groupId><artifactId>testng</artifactId></exclusion></exclusions></dependency>(...)
</dependencies>
通常在我們的項目中使用較新的TestNG版本,因此應該排除ReportNG依賴項。
接下來,必須配置Surefire插件:
<build><plugins><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></configuration></plugin>(...)</plugins>
</build>
ReportNG使用兩個可插入TestNG的報告程序。 JUnitXMLReporter生成運行測試的XML摘要。 它用于工具(例如CI服務器)。 HTMLReporter創建可讀HTML報告。 默認的TestNG偵聽器應被禁用。
在測試運行后,我還添加了workingDirectory屬性,該屬性導致將Velocity.log(由ReportNG內部使用的Velocity引擎創建的文件)放置在目標中而不是主項目目錄中(并因此通過“ mvn clean”命令刪除)。
還有一件事。 不幸的是,ReportNG jar在Maven中央存儲庫中不可用,因此可能需要在settings.xml中添加java.net存儲庫。
<repositories><repository><id>java-net</id><url>http://download.java.net/maven/2</url></repository>(...)
</repositories>
就這樣。 現在,“ MVN干凈測試”應該為包含我們項目的許多測試生成漂亮HTML報告。
參考: 使用ReportNG更好看的TestNG HTML測試報告–來自Solid Soft博客的JCG合作伙伴 Marcin Zajaczkowski的Maven指南 。
翻譯自: https://www.javacodegeeks.com/2012/05/better-looking-html-test-reports-for.html