在进行单元测试时,测试出现异常

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.xmlorg.junit.jupiter依赖 
2、Reimport All Maven Project

最新文章

  1. iOS之 开发常用到的宏定义
  2. js-变量
  3. python学习之操作mysql
  4. Hibernate3回顾-6-hibernate缓存(性能优化策略)
  5. 准备学一学go-lang啦 ~~ 学习Go应该用什么姿势? !
  6. 理解CSS中的三种选择器&gt;+~
  7. Java 网络编程(Elliotte Rusty Harold)
  8. git简单使用教程
  9. HUST 1372 marshmallow
  10. 51驱动LCD1602
  11. 嵌套的Try-Catch块--------异常处理(3)
  12. 如何打一个FatJar(uber-jar)
  13. FaceRank-项目上了 GitHub Python Trending
  14. C# Winform 自适应
  15. WebForm应用log4net记录错误日志——使用线程列队写入
  16. Linux IDR机制【转】
  17. adb devices检测不到夜神模拟器
  18. 支持辉光效果的Label
  19. C#绘制数字图像灰度直方图
  20. Linux基础命令---bc

热门文章

  1. Mybatis中jdbcType和javaType、typeHandler的对照关系
  2. 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
  3. suoi31 最近公共祖先2 (倍增lca)
  4. ssm controller层 junit单元测试
  5. Flask-SQLAlchemy 无法创建Sqlite 数据库???
  6. Java基础-使用Idea进行远程调试
  7. javaweb购物车实现的几种方式
  8. 解决pdf打印预览中遇到特殊字符,导出失败问题
  9. 数据库类型与JDBC TYPE 和Java类型对应关系
  10. bzoj千题计划231:bzoj1997: [Hnoi2010]Planar