Maven中使用reportNG,并自定义reportNG output中的log

转自:http://www.cnblogs.com/qianyiliushang/p/4256037.html


众所周知,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的成功率覆盖率等


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值