Apache Maven项目提供的Surefire插件详解

1.插件goal

Surefire插件包含的唯一goal就是surefire:test,执行单元测试。

其使用TestNG进行测试的时候,可以有两类配置方法。一类是在pom.xml文件中添加对TestNG的依赖,然后再Surefire插件的configuration中根据测试类的特征配置要进行的测试。这类的典型配置如下:

[html]  view plain  copy
  1. <dependencies>  
  2.   ...  
  3.     <dependency>  
  4.       <groupId>org.testng</groupId>  
  5.       <artifactId>testng</artifactId>  
  6.       <version>6.9.8</version>  
  7.       <scope>test</scope>  
  8.     </dependency>  
  9.   ...  
  10. </dependencies>  
  11. <build>  
  12.   <plugins>  
  13.     <plugin>  
  14.       <groupId>org.apache.maven.plugins</groupId>  
  15.       <artifactId>maven-surefire-plugin</artifactId>  
  16.       <version>2.19.1</version>  
  17.       <configuration>  
  18.         <includes>  
  19.           <include>%regex[.*[Cat|Dog].*Test.*]</include>  
  20.         </includes>  
  21.         <excludes>  
  22.           <exclude>**/TestCircle.java</exclude>  
  23.           <exclude>**/TestSquare.java</exclude>  
  24.         </excludes>  
  25.       </configuration>  
  26.     </plugin>  
  27.   </plugins>  
  28. </build>  


另一类是在pom.xml文件中,直接通过TestNG的suite文件,执行其中的测试,而忽略测试类本身的特征。这类的典型配置如下:

[html]  view plain  copy
  1. <plugins>  
  2.     ...  
  3.       <plugin>  
  4.         <groupId>org.apache.maven.plugins</groupId>  
  5.         <artifactId>maven-surefire-plugin</artifactId>  
  6.         <version>2.19.1</version>  
  7.         <configuration>  
  8.           <suiteXmlFiles>  
  9.             <suiteXmlFile>mytestng.xml</suiteXmlFile>  
  10.           </suiteXmlFiles>  
  11.         </configuration>  
  12.       </plugin>  
  13.     ...  
  14. </plugins>  

2.测试报告

Surefire插件还能够生成测试报告,并以txt或者XML格式保存在${basedir}/target/surefire-reports路径下。

如果要生成HTML格式的测试报告,就只能使用Surefire Report插件了。



3.Surefire插件官网

http://maven.apache.org/surefire/maven-surefire-plugin/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值