当前位置:网站首页>Junit4运行mvn test 测试套件升级方案
Junit4运行mvn test 测试套件升级方案
2022-07-02 06:35:00 【别说小李】
背景:
项目中包含了junit4(独立引入) 和junit5(spring-boot-starter-parent 2.5.4自带版本)
目前我们使用的springboot 3.5.4自带的maven-surefire-plugin 版本为:2.22.2
其加载逻辑如下: 会按照junit5的规则查找测试,但是我们suit套件使用的是junit4版本,导致出现找不到单元测试异常。
if the JUnit 5 Platform Engine is present in the project
use junit-platform
if the JUnit version in the project >= 4.7 and the <<<parallel>>> configuration parameter has ANY value
use junit47 provider
if JUnit >= 4.0 is present
use junit4 provider
else
use junit3.8.1
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
异常信息:
执行数量为0:[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
或者mvn -Dtest=TestSuiteOne test
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project wdseller-web: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
解决方案:
- 第一种方案:全局升级到junit5
- 第二种方案:指定maven-surefire-plugin 到一个老的版本
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<includes>
<include>com.wdtrip.seller.controller.TestSuiteOne</include>
</includes>
</configuration>
</plugin>其它:suit套件执行方法
- mvn -Dtest=TestSuiteOne test (通过指定测试suit,直接执行)
- 如上pom配置maven-surefire-plugin 的include后,直接执行mvn test ,效果相同
参考文档:
官方文档:Maven Surefire Plugin – Using JUnit
csdn:测试开发基础 mvn test | 利用 Maven Surefire Plugin 做测试用例基础执行管理 - 云+社区 - 腾讯云
Why Your JUnit 5 Tests Are Not Running Under Maven - Spring Framework Guru

边栏推荐
- 2837xd Code Generation - Supplement (1)
- Chrome browser plug-in fatkun installation and introduction
- Web security and defense
- 定时线程池实现请求合并
- Hystrix implements request consolidation
- Typora安装包分享
- 2837xd Code Generation - stateflow (4)
- Required request body is missing:(跨域问题)
- C language programming problems
- MySQL default transaction isolation level and row lock
猜你喜欢

QT qlabel style settings

idea查看字节码配置

How to install PHP in CentOS

Timed thread pool implements request merging

c语言编程题

Hystrix implements request consolidation

YOLO物体识别,生成数据用到的工具

Off grid control of three-phase inverter - PR control

定时线程池实现请求合并

2837xd code generation module learning (4) -- idle_ task、Simulink Coder
随机推荐
分布式锁的这三种实现方式,如何在效率和正确性之间选择?
Image recognition - data annotation
Record the interesting process of using Xray for the first time
Bugkuctf-web21 (detailed problem solving ideas and steps)
Int to string, int to qstring
2837xd 代码生成——StateFlow(4)
Share a blog (water blog)
自定義Redis連接池
ZK configuration center -- configuration and use of config Toolkit
QT qlabel style settings
The road is blocked and long, and the line is coming
CKEditor 4.10.1 上传图片提示“不正确的服务器响应” 问题解决
Knife4j 2. Solution to the problem of file control without selection when uploading x version files
道阻且长,行则将至
互联网API接口幂等设计
Mysql 多列IN操作
一次聊天勾起的回忆
VIM操作命令大全
C language programming problems
2837xd 代碼生成——補充(1)