qianyiliushang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

众所周知,testNG自带的report不太美观,所以我们这里用到了reportNG来生成report,加入reportNG很简单,只需在pom.xml中加入以下配置

 1 <dependency>
 2             <groupId>org.uncommons</groupId>
 3             <artifactId>reportng</artifactId>
 4             <version>1.1.4</version>
 5             <exclusions>
 6                 <exclusion>
 7                     <groupId>org.testng</groupId>
 8                     <artifactId>testng</artifactId>
 9                 </exclusion>
10             </exclusions>
11         </dependency>
12 
13         <dependency>
14             <groupId>com.google.inject</groupId>
15             <artifactId>guice</artifactId>
16             <version>4.0-beta5</version>
17         </dependency>

需要注意的一点是还需加入guice这个包,否则在执行mvn test的时候会编译不通过,报ClassNotFoundException

下面是配置maven-surefire-plugin并加入reportNG listenser

 1 <plugins>
 2             <plugin>
 3                 <groupId>org.apache.maven.plugins</groupId>
 4                 <artifactId>maven-surefire-plugin</artifactId>
 5                 <version>2.18.1</version>
 6                 <configuration>
 7                     <properties>
 8                         <property>
 9                             <name>userdefaultlisteners</name>
10                             <value>false</value>
11                         </property>
12                         <property>
13                             <name>listener</name>
14                             <value>org.uncommons.reportng.HTMLReporter,
15                                 org.uncommons.reportng.JUnitXMLReporter,
16                                 </value>
17                         </property>
18                     </properties>
19                     <workingDirectory>target/</workingDirectory>
20                 </configuration>
21             </plugin>

这里要将defaultListener设置为false,下面配置了两个listener,一个是HTMLReport,用来生成HTML格式的Report,别一个是JUnitXMLReporter,这个是用来生成xml格式的report,用于jekins服务器

 

有了报告以后,我们会想,能不能在case执行的过程中将一些重要的log信息也输出到report中呢?

testNG中有这样一个类:Reporter,就是专门做这个工作的,通常我们可以封装一个通用的方法来处理这种情况:

 1 /**
 2  * Created by zombie on 2015年1月24日
 3  * chen_peng06@163.com
 4  */
 5 package com.zombie.test.utils;
 6 
 7 import org.testng.Reporter;
 8 
 9 /**
10  * @author zombie 
11  * Add log info into html report
12  */
13 public class LogUtil {
14     public static void info(String s) {
15         Reporter.log(s.toString().trim());
16     }
17 }

 

这样生成的报告就既美观又实用了,后续会研究自定义listener,添加case的成功率覆盖率等

posted on 2015-01-28 15:39  qianyiliushang  阅读(2320)  评论(0编辑  收藏  举报