1

I am getting this java.lang.ExceptionInInitializationError when I use the 4.2.3.RELEASE version of spring-test. However, the code works fine with the 4.0.5.RELEASE. I'm using Junit 4.7. Can someone please help me figure out why the version change induces this error? All my other spring jars are on 4.2.3.RELEASE version My test looks like this:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:/servlet-context.xml","classpath:root-context.xml"})
public class TestCarFactory {
    @Autowired
    private ICarFactory carFactory;

    @Test
    public void testCarFactory() {
        String audiMName = carFactory.getCar("Audi").getCarManufacturer();
        String lexusMName= carFactory.getCar("Lexus").getCarManufacturer();
        String hondaMName = carFactory.getCar("Honda").getCarManufacturer();

        assertEquals("Volkswagen", audiMName);
        assertEquals("Toyota", lexusMName);
        assertEquals("Honda", hondaMName);
    }
}

The exception trace:

java.lang.ExceptionInInitializerError
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
        at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
        at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
        at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
        at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
        at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
    Caused by: java.lang.IllegalStateException: Failed to find class [org.junit.runners.model.MultipleFailureException]: SpringJUnit4ClassRunner requires JUnit 4.9 or higher.
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<clinit>(SpringJUnit4ClassRunner.java:102)
        ... 17 more
Prune
  • 76,765
  • 14
  • 60
  • 81

1 Answers1

2

This is a duplicate of this issue: Why the cryptic MultipleFailureException error message with the SpringJUnit4ClassRunner.withAfterClasses method

Perhaps more importantly, why did you not actually read the stack trace?!

Caused by: java.lang.IllegalStateException: Failed to find class [org.junit.runners.model.MultipleFailureException]: SpringJUnit4ClassRunner requires JUnit 4.9 or higher.

SpringJUnit4ClassRunner requires JUnit 4.9 or higher.

That says it all.

Community
  • 1
  • 1
Sam Brannen
  • 29,611
  • 5
  • 104
  • 136
  • 1
    Hi, I have upgraded Junit version to 4.9 in my project, but still, I am getting the same error. – Pruthviraj Apr 27 '17 at 13:28
  • 1
    If you're getting a message from Spring that JUnit 4.9 is required, then you have not successfully upgraded your project to use JUnit 4.9. For example, you may be pulling in different versions of JUnit as transitive dependencies. So verify how JUnit is pulled into your dependency graph. – Sam Brannen Apr 27 '17 at 13:37
  • Thanks a lot for your response, I have upgraded Junit version to 4.9 in my project, but I am still getting error message " java.lang.IllegalStateException: SpringJUnit4ClassRunner requires JUnit 4.12 or higher." I have added following in pom.xml junit junit 4.9 test – Pruthviraj Apr 28 '17 at 04:58
  • 1
    Hi Sam Brannen, I am able to solve my problem, The problem was, all the other spring jars I was using are version 4.2.4, but spring-test I include, is from version 4.3.8. Now I down-graded it to 4.2.4 and it's started working. – Pruthviraj Apr 28 '17 at 06:42