maven-surefire-plugin 单元测试套件
前言
众所周知,Junit可用于单元测试,maven编译的时候也可以整体执行测试用例,但是很多时候测试用例过多,并且我们不希望老是重复执行已经验证过没有问题的用例而耗费时间,这个时候就要用到测试集了,也就是说通过配置的形式有针对性的对需要测试的用例进行检查!
Junit本身提供了测试套件,但是这个测试集不能生成测试报告,大家可以有选择性的参考下:
https://www.w3cschool.cn/junit/36em1hv1.html
我们今天介绍的是apache maven提供的一个集测试套件和测试报告的插件:maven-surefire-plugin
使用
依赖坐标
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> surefire-setting.xml --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.math=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED
测试用例
跟普通的Junit测试用例唯一的区别就是@Test需要使用org.junit.jupiter.api.Test才能被插件扫描到
surefire-setting.xml测试集配置
项目根路径编写
*/test21/*
**/Test22*.java
test1.Test1.java
这个地方其实任何文件都可以(本人已测试),只要配置的测试集是一行一行的即可,但是看标签源码是如上格式,那就按规矩来!
执行脚本
项目根路径编写surefire.sh,当然,你在根目录下直接执行如下命令也可!
mvn clean surefire-report:report
执行脚本后,可以看到项目target目录下多了两个目录surefire-reports、site,打开site目录下的测试报告文件如下:
文章链接
发表评论