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

来源:互联网 发布:java 数组去重的方法 编辑:程序博客网 时间:2024/05/17 09:13

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/


1 0
原创粉丝点击