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

编程入门 行业动态 更新时间:2024-10-04 13:32:18

Apache Maven项目提供的Surefire插件<a href=https://www.elefans.com/category/jswz/34/1770044.html style=详解"/>

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插件官网

/


更多推荐

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

本文发布于:2024-02-28 14:03:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1769865.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:详解   插件   项目   Apache   Maven

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!