Caused by: java.lang.IllegalStateException: SpringJUnit4ClassRunner requires JUnit 4.12 or higher.

1java.lang.ExceptionInInitializerError 2 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 3 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 4 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 5 at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 6 at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31) 7 at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24) 8 at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57) 9 at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29) 10 at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57) 11 at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24) 12 at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:33) 13 at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49) 14 at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) 15 at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230) 16 at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58) 17Caused by: java.lang.IllegalStateException: SpringJUnit4ClassRunner requires JUnit 4.12 or higher. 18 at org.springframework.util.Assert.state(Assert.java:73) 19 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<clinit>(SpringJUnit4ClassRunner.java:104) 20 ... 15 more 21 22 23

在这里插入图片描述

当使用spring 5.x版本的时候,要求junit的jar包必须是4.12及以上,换jar包版本就可以解决问题。

代码交流 2021