栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Junit4运行mvn test 测试套件升级方案

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Junit4运行mvn test 测试套件升级方案

背景:

项目中包含了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 <<>> configuration parameter has ANY value
    use junit47 provider
if JUnit >= 4.0 is present
    use junit4 provider
else
    use junit3.8.1

       2.22.2


          org.apache.maven.plugins
          maven-surefire-plugin
          ${maven-surefire-plugin.version}
        
        
        

异常信息:

执行数量为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]

解决方案:
  1. 第一种方案:全局升级到junit5
  2. 第二种方案:指定maven-surefire-plugin 到一个老的版本

                org.apache.maven.plugins
                maven-surefire-plugin
                2.19.1
                
                    
                        com.wdtrip.seller.controller.TestSuiteOne
                    
                
            

其它:suit套件执行方法
  1. mvn -Dtest=TestSuiteOne test (通过指定测试suit,直接执行)
  2. 如上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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/962595.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号