Better looking HTML test reports for TestNG with ReportNG – Maven guide

上一篇 / 下一篇  2012-03-05 15:46:04 / 个人分类:testng

转自 http://solidsoft.wordpress.com/2011/01/23/better-looking-html-test-reports-for-testng-with-reportng-maven-guide/

TestNG is a testing framework created as an annotation driven alternative for JUnit 3 in times when “extends TestCase” was a indispensable part of writing tests. Even now it provides some interesting features like data providers, parallel tests or test groups. In the situation our tests are not executed from IDE it’s often useful to take a look at test result in HTML report. The original TestNG report looks… raw. What is more they are not very intuitive and readable. There is an alternative – ReportNG. It provides better looking and more lucid HTML test reports.

More information about ReportNG can be found at its webpage, but when I tried to use for my AppInfo library in Maven builds running from CI server I had a problem to find any at a glance guide how to use it with Maven. Fortunately there are samples for Ant and Gradle, so I was able to figure it out, but I hope with this post everyone wanting to use ReportNG with Maven will be able to achieve it without any problem within a few minutes.

First, additional dependency has to be added to pom.xml:

01<dependencies>
02    <dependency>
03        <groupId>org.uncommons</groupId>
04        <artifactId>reportng</artifactId>
05        <version>1.1.2</version>
06        <scope>test</scope>
07        <exclusions>
08            <exclusion>
09                <groupId>org.testng</groupId>
10                <artifactId>testng</artifactId>
11            </exclusion>
12        </exclusions>
13    </dependency>
14    (...)
15</dependencies>

Usually in our project newer TestNG version is used, so that ReportNG dependency should be excluded.

Next, Surefire plugin has to be configured:

01<build>
02    <plugins>
03        <plugin>
04            <groupId>org.apache.maven.plugins</groupId>
05            <artifactId>maven-surefire-plugin</artifactId>
06            <version>2.5</version>
07            <configuration>
08                <properties>
09                    <property>
10                        <name>usedefaultlisteners</name>
11                        <value>false</value>
12                    </property>
13                    <property>
14                        <name>listener</name>
15                        <value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value>
16                    </property>
17                </properties>
18                <workingDirectory>target/</workingDirectory>
19            </configuration>
20        </plugin>
21        (...)
22    </plugins>
23</build>

ReportNG uses two reporters pluggable into TestNG. JUnitXMLReporter generates XML summarize of running tests. It’s used for tools (like CI server). HTMLReporter creates human readable HTML report. Default TestNG listeners should be disabled.

After test run I added also workingDirectory property which causes that velocity.log (file created by Velocity engine used internally by ReportNG) is placed in target instead of main project directory (and therefor is deleted by “mvn clean” command).

One more thing. Unfortunately ReportNG jar isn’t available in Maven Central Repository, so could be required to add java.net repository in your settings.xml.

1<repositories>
2    <repository>
3        <id>java-net</id>
4        <url>http://download.java.net/maven/2</url>
5    </repository>
6    (...)
7</repositories>

That’s all. Now “mvn clean test” should generate nice looking HTML report for lots of tests covering our project:).


TAG:

 

评分:0

我来说两句

日历

« 2024-05-15  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 4728
  • 日志数: 14
  • 建立时间: 2012-02-29
  • 更新时间: 2012-03-16

RSS订阅

Open Toolbar