I am getting the following exception from a test case that ran successfully before but now it throws this exception:
java.lang.NoSuchMethodError: junit.framework.ComparisonFailure.getExpected()Ljava/lang/String; at org.eclipse.jdt.internal.junit4.runner.JUnit4TestListener.testFailure(JUnit4TestListener.java:63) at org.junit.runner.notification.RunNotifier$4.notifyListener(RunNotifier.java:100) at org.junit.runner.notification.RunNotifier$SafeNotifier.run(RunNotifier.java:41) at org.junit.runner.notification.RunNotifier.fireTestFailure(RunNotifier.java:97) at org.junit.internal.runners.JUnit38ClassRunner$OldTestClassAdaptingListener.addError(JUnit38ClassRunner.java:41) at org.junit.internal.runners.JUnit38ClassRunner$OldTestClassAdaptingListener.addFailure(JUnit38ClassRunner.java:64) at junit.framework.TestResult.addFailure(TestResult.java:46) at junit.framework.TestResult.runProtected(TestResult.java:127) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Anyone know what is causing this? It seems like an internal issue with the JUnit runner.
The getExpected()
method on junit.framework.ComparisonFailure
was only added in JUnit 3.8.2 (remember, junit.framework
package is from JUnit 3.8, whereas JUnit 4 uses org.junit
). The method wasn't there in 3.8.1, which is the most common version of 3.x still out there.
I think the method was added for easier migration to JUnit 4 tooling, and occasionally this exception pops up on older code bases that use JUnit 3.8. The Eclipse JUnit 4 test runner would appear to switch back to calling the junit.framework.*
code when running JUnit 3.8 tests.
SO I'm guessing you still have JUnit 3.8.1 lurking about on your classpath, and it's clashing with the Eclipse test runner. Either get rid of that JAR, or "upgrade" it to 3.8.2.
This can also occur if you're using JUnit 4 but import the Assert
class from the old junit.framework
package (rather than the new org.junit
package)
Check both your imports and your static imports - the culprit for me was import static junit.framework.Assert.assertEquals;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With