JUnit 3.8 or later expected with java.lang.NoSuchMethodError: junit.textui.TestRunner.setPrinter

I have been trying to run junit through intellij and the test fails to executes. I get the following message on the intellij

!!! JUnit version 3.8 or later expected: java.lang.NoSuchMethodError: junit.textui.TestRunner.setPrinter(Ljunit/textui/ResultPrinter;)V      at com.intellij.rt.execution.junit.JUnitStarter.junitVersionChecks(JUnitStarter.java:191)      at com.intellij.rt.execution.junit.JUnitStarter.canWorkWithJUnitVersion(JUnitStarter.java:174)      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:57)      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)      at java.lang.reflect.Method.invoke(Method.java:606)      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)


However when I run the following mvn commnd the test passes

mvn clean test


This is the class path

/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/bin/java -ea -Didea.launcher.port=7539 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 14 CE.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA 14 CE.app/Contents/lib/idea_rt.jar:/Applications/IntelliJ IDEA 14 CE.app/Contents/plugins/junit/lib/junit-rt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/lib/javafx-doclet.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/htmlconverter.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Users/brajakumar/Documents/hello1234/target/test-classes:/Users/brajakumar/Documents/hello1234/target/classes:/Users/brajakumar/.m2/repository/junit/junit/4.11/junit-4.11.jar:/Users/brajakumar/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar" com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 com.something.AppTest


Could someone tell me what is wrong here? Thanks.

7 comments
Comment actions Permalink

Please see my answer at http://stackoverflow.com/a/2431427/104891 .

Check the classpath when you run test from IDEA. There could be some other library jar with older JUnit version that appears first in the classpath.

0
Comment actions Permalink

I dont see any older versions of junit in my classpath. I tried moving up the order of Junit and still no luck. I created a similar maven project with Eclipse and it worked like a charm. Do both the IDE add different set of JAR files when a specific JDK is used??

0
Comment actions Permalink

Hard to say, attach a sample project to reproduce the problem.

0
Comment actions Permalink

I have attached two zipped versions of the project folder. One was used in intellij which contains the .iml file and the other one contains the .settings file which is used by eclipse. The eclipse project works fine but the intellij one doesn't work as of yet.  



Attachment(s):
helloTest.zip
helloTest.zip
0
Comment actions Permalink

This project compiles and runs without issues in IntelliJ IDEA:

http://i.imgur.com/kNsrDpK.png

0
Comment actions Permalink

You may have some old JUnit jars that may be loaded by Java from the following folders:

/Library/Java/Extensions/
~/Library/Java/Extensions

Make sure these folders are empty.

0
Comment actions Permalink

Gotcha, I had a couple of JAR files under the folder /Library/Java/Extensions/ as you had mentioned earlier. One of them was Junit 3.7. Once I removed all the JAR files, the JUnit test worked like a charm. Thank you so much SIR !!!

0

Please sign in to leave a comment.