当前位置: 首页 > news >正文

集成测试,单元测试隔离 maven-surefire-plugin

详见 集成测试,单元测试隔离 maven-surefire-plugin

maven的goal生命周期

Maven生存周期 - 含 integration-test

Maven本身支持的命令(Goals)是有顺序的,越后面执行的命令,会将其前面的命令和其本身按顺序执行一遍,具体的顺序如下所示:

validate
initialize
generate-sources
process-sources
generate-resources
process-resources
compile
process-classes
generate-test-sources
process-test-sources
generate-test-resources
process-test-resources
test-compile
process-test-classes
test
prepare-package
package
pre-integration-test
integration-test
post-integration-test
verify
install

从上面maven的生存期可以看出



作者:哈比猪
链接:https://www.jianshu.com/p/e638d64b6955/
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

maven单元测试与集成测试

  1. 通过maven的Profile
  2. 配置生命周期 通过maven-surefire-plugin的生命周期配置不同的测试范围

如下使用的是方式2

unit包中包含的是单元测试

integration包种包含的是集成测试

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.9</version><configuration><skip>true</skip></configuration><executions><execution><id>run-integration-test</id><phase>integration-test</phase><goals><goal>test</goal></goals><configuration><skip>false</skip><includes><include>**/integration/**/*.java</include></includes></configuration></execution><execution><id>run-test</id><phase>test</phase><goals><goal>test</goal></goals><configuration><skip>false</skip><includes><include>**/unit/**/*.java</include></includes></configuration></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>2.0</version><configuration><dependentWarExcludes>WEB-INF/lib</dependentWarExcludes></configuration></plugin></plugins>

maven-failsafe-plugin 配置POM.XML

实际上POM.XML提供了很强大的配置功能,这里利用一个maven的插件,叫maven-failsafe-plugin,具体配置如下:

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-failsafe-plugin</artifactId><version>2.17</version><executions><execution><id>integration-tests</id><goals><goal>integration-test</goal><goal>verify</goal></goals><configuration><excludes><exclude>none</exclude></excludes><includes><include>**/*IT.java</include></includes></configuration></execution></executions>
</plugin>

这里创建了一个execution,当执行integration-test goal的时候,执行包括“IT.java”结尾的所有java文件,那如何跳过unit test,integration-test呢?看下面利用了另外一个插件,叫maven-surefire-plugin,如下配置:

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.6</version><configuration><skip>false</skip></configuration>
</plugin>

通过skip标签来指定跳过test的行为,默认是支持skipITsskipTests,前者是跳过integration-test,后者是跳过所有的测试(稍微说明下,跳过测试方法有很多种,比如maven-failsafe-plugin本身也支持加入skip选项,只不过实现之后每个命令的含义就略微有不同了,大家选择自己最习惯的就好了).

  •  推荐的测试目录结构

Unit Test Classes        : src/test/java/**/**Test.java
Integration Test Classes : src/test/java/**/**IT.java
TestCases dependent files: src/test/resources/*

http://www.lryc.cn/news/102183.html

相关文章:

  • 渗透测试基础知识(1)
  • Android NDK开发
  • 使用python爬取淘宝商品信息
  • QEMU源码全解析18 —— QOM介绍(7)
  • 【华为OD机试】 选修课
  • 225. 用队列实现栈
  • IDEA将本地项目上传到码云
  • Ubuntu更改虚拟机网段(改成桥接模式无法连接网络)
  • 谷粒商城第七天-商品服务之分类管理下的删除、新增以及修改商品分类
  • Redis学习路线(1)—— Redis的安装
  • 《MySQL 实战 45 讲》课程学习笔记(五)
  • 使用GADL对高程数据进行填洼
  • Spring Boot集成Swagger3.0,Knife4j导出文档
  • 在.NET Framework中的连接字符串ConnectionStrings属性
  • kafka消费报错卡死:内存溢出OutOfMemoryError: Java heap space
  • mac卸载与安装指定版本node
  • 机器学习深度学习——Dropout
  • Intel和AMD 与 x86,ARM,MIPS有什么区别?
  • QT编写的串口助手
  • C语言字符串的处理
  • Docker 阿里云容器镜像服务
  • 10kV 电力电缆交流耐压试验方案
  • 【雕爷学编程】MicroPython动手做(20)——掌控板之三轴加速度6
  • 链路 聚合
  • DPN(Dual Path Network)网络结构详解
  • 【转载】Gin框架优雅退出
  • 【数字IC设计】VCS仿真DesignWare IP
  • 【*1900 图论+枚举思想】CF1328 E
  • AutoSAR系列讲解(实践篇)10.5-通信管理模块
  • 2023.7.30(epoll实现并发服务器)