unit测试出现异常:Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util
2024-10-12 16:33:45
在进行单元测试时,测试出现异常
Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader;
at org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry.loadTestEngines(ServiceLoaderTestEngineRegistry.java:30)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:53)
at com.intellij.junit5.JUnit5IdeaTestRunner.createListeners(JUnit5IdeaTestRunner.java:39)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:49)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
https://junit.org/junit5/docs/current/user-guide/#running-tests-ide-intellij-idea
pom.xml
依赖如下
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
问题原因
错误就在pom.xml
的依赖中,仔细查看控制台输出你会发现IntelliJ IDEA正在尝试使用JUnit5运行我的测试用例。
at com.intellij.junit5.JUnit5IdeaTestRunner.createListeners(JUnit5IdeaTestRunner.java:39)
通过pom.xml
发现,我希望使用JUnit4.12运行测试用例,我们查看pom.xml
发现junit-jupiter-api这个依赖会导致这个错误。
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>RELEASE</version>
</dependency>
因为此模块专为JUnit5而设计 -https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
解决方案
1、删除
pom.xml
中org.junit.jupiter
依赖
2、Reimport All Maven Project
最新文章
- iOS之 开发常用到的宏定义
- js-变量
- python学习之操作mysql
- Hibernate3回顾-6-hibernate缓存(性能优化策略)
- 准备学一学go-lang啦 ~~ 学习Go应该用什么姿势? !
- 理解CSS中的三种选择器>;+~
- Java 网络编程(Elliotte Rusty Harold)
- git简单使用教程
- HUST 1372 marshmallow
- 51驱动LCD1602
- 嵌套的Try-Catch块--------异常处理(3)
- 如何打一个FatJar(uber-jar)
- FaceRank-项目上了 GitHub Python Trending
- C# Winform 自适应
- WebForm应用log4net记录错误日志——使用线程列队写入
- Linux IDR机制【转】
- adb devices检测不到夜神模拟器
- 支持辉光效果的Label
- C#绘制数字图像灰度直方图
- Linux基础命令---bc
热门文章
- Mybatis中jdbcType和javaType、typeHandler的对照关系
- Could not load file or assembly &#39;Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91&#39; or one of its dependencies
- suoi31 最近公共祖先2 (倍增lca)
- ssm controller层 junit单元测试
- Flask-SQLAlchemy 无法创建Sqlite 数据库???
- Java基础-使用Idea进行远程调试
- javaweb购物车实现的几种方式
- 解决pdf打印预览中遇到特殊字符,导出失败问题
- 数据库类型与JDBC TYPE 和Java类型对应关系
- bzoj千题计划231:bzoj1997: [Hnoi2010]Planar