Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringJUnit4ClassRunner.runleaf method not found

I am getting error when run test code using ant script. But If I run testMethods using eclipse separately by RUN AS -> JUNIT that's return correct answer.

java.lang.NoSuchMethodError: org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runLeaf(Lorg/junit/runners/model/Statement;Lorg/junit/runner/Description;Lorg/junit/runner/notification/RunNotifier;)V
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)

I am using junit:4.12 and spring-test:4.3.16.RELEASE library. I have searched for solution but every solution gives answer me to use junit version greater than junit:11. But I am using 4.12 but still getting error.

like image 227
flopcoder Avatar asked Feb 21 '26 02:02

flopcoder


1 Answers

  The problem is caused by pom dependency. It didn't work whatever you change your junit version is because there are some other pom dependencies that introduced old junit version indirectly before load the Junit dependency that you explicitly defined in POM. To see this, enter class SpringJUnit4ClassRunner, and then enter its super class BlockJUnit4ClassRunner, you will find it doesn't lie in the junit jar package you declared in POM.

  So, to solve this problem, you should find out which pom dependency indirect introduce the jar package you find in paragraph 1 through: mvn dependency:tree, and then use exclusion to exclude it in the corresponding pom dependency, such as:
<exclusion> <groupId>org.junit</groupId> <artifactId>com.springsource.org.junit</artifactId> </exclusion>

  Now, it should work correctly! (If don't, you may need mvn clean install)

like image 89
Tom.monkey Avatar answered Feb 23 '26 02:02

Tom.monkey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!