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

Surefire插件用于Maven项目的test阶段,以执行单元测试。最新版本是2015.12.31发布的2.19.1。


1.插件goal

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

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

<dependencies>
  ...
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.9.8</version>
      <scope>test</scope>
    </dependency>
  ...
</dependencies>
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.19.1</version>
      <configuration>
        <includes>
          <include>%regex[.*[Cat|Dog].*Test.*]</include>
        </includes>
        <excludes>
          <exclude>**/TestCircle.java</exclude>
          <exclude>**/TestSquare.java</exclude>
        </excludes>
      </configuration>
    </plugin>
  </plugins>
</build>


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

<plugins>
    ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>mytestng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
      </plugin>
    ...
</plugins>

2.测试报告

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

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



3.Surefire插件官网

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值