当前位置:网站首页>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

边栏推荐
- QT QLabel样式设置
- Bugkuctf-web24 (problem solving ideas and steps)
- Activity的创建和跳转
- Alibaba /热门json解析开源项目 fastjson2
- Read 30 minutes before going to bed every day_ day3_ Files
- MySQL error: unblock with mysqladmin flush hosts
- Required request body is missing: (cross domain problem)
- 一次聊天勾起的回忆
- Binary and decimal system of C language
- 2837xd code generation - stateflow (4)
猜你喜欢

PI control of three-phase grid connected inverter - off grid mode

2837xd 代码生成——补充(3)

2837xd code generation module learning (4) -- idle_ task、Simulink Coder

Insight into cloud native | microservices and microservice architecture

Record the interesting process of using Xray for the first time

Say goodbye to 996. What are the necessary plug-ins in idea?

攻防世界-Web进阶区-unserialize3

Operation and application of stack and queue

2837xd 代码生成——补充(1)

Personal experience & blog status
随机推荐
图像识别-数据标注
Web security and defense
Because of hard work, the fruit goes with fate
How to install PHP in CentOS
Typora installation package sharing
idea查看字节码配置
2837xd Code Generation - Supplement (1)
zk配置中心---Config Toolkit配置与使用
图像识别-数据增广
保存视频 opencv::VideoWriter
Chrome browser plug-in fatkun installation and introduction
Judging right triangle in C language
分布式锁的这三种实现方式,如何在效率和正确性之间选择?
企业级SaaS CRM实现
BugkuCTF-web16(备份是个好习惯)
2837xd code generation module learning (4) -- idle_ task、Simulink Coder
Chrome user script manager tempermonkey monkey
Navicat remote connection MySQL reports an error 1045 - access denied for user 'root' @ '222.173.220.236' (using password: yes)
Bugkuctf-web24 (problem solving ideas and steps)
Break the cocoon | one article explains what is the real cloud primordial