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
1
  • Cleaned up formatting; minor edits. Commented Nov 20, 2015 at 17:25

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Hi, I have upgraded Junit version to 4.9 in my project, but still, I am getting the same error.
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.
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 <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.9</version> <scope>test</scope> </dependency>
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.