在进行单元测试时,测试出现异常java
Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader;
错误就在pom.xml
的依赖中,仔细查看控制台输出你会发现IntelliJ IDEA正在尝试使用JUnit5运行个人测试用例。spring
at com.intellij.junit5.JUnit5IdeaTestRunner.createListeners(JUnit5IdeaTestRunner.java:39)
经过pom.xml
发现,我但愿使用JUnit4.12运行测试用例,咱们查看pom.xml
发现junit-jupiter-api这个依赖会致使这个错误。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单元测试
解决方案测试
一、删除
pom.xml
中org.junit.jupiter
依赖
二、Reimport All Maven Projectspa