9

I'm attempting to run a simple JUnit test case on version 3.7 of JUnit (I'm not able to upgrade this to the latest version)

Running IntelliJ, I get the following exception when I attempt to run my JUnit testcase :

Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:108)
Caused by: java.lang.ClassNotFoundException: junit.textui.ResultPrinter
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    ... 3 more

Process finished with exit code 1

I have IntelliJ version 10.0.2, JUnit 3.7 on my classpath and the IntelliJ plugin which states it supports 3.x and 4.x

I can see IntelliJ executing the following (added breaks to make it more readable)

"C:\Program Files\Java\jdk1.6.0_20\bin\java" -Didea.launcher.port=7532 
    "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 10.0\bin" 
    -Dfile.encoding=windows-1252 
    -classpath "C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 10.0\lib\idea_rt.jar;
                C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 10.0\plugins\junit\lib\junit-rt.jar;
                C:\Program Files\Java\jdk1.6.0_20\jre\lib\alt-rt.jar;
                C:\Program Files\Java\jdk1.6.0_20\jre\lib\charsets.jar;
                C:\Program Files\Java\jdk1.6.0_20\jre\lib\deploy.jar;
                C:\Program Files\Java\jdk1.6.0_20\jre\lib\javaws.jar;
                C:\Program Files\Java\jdk1.6.0_20\jre\lib\jce.jar;
                C:\Program Files\Java\jdk1.6.0_20\jre\lib\jsse.jar;
                C:\Program Files\Java\jdk1.6.0_20\jre\lib\management-agent.jar;
                C:\Program Files\Java\jdk1.6.0_20\jre\lib\plugin.jar;
                C:\Program Files\Java\jdk1.6.0_20\jre\lib\resources.jar;
                C:\Program Files\Java\jdk1.6.0_20\jre\lib\rt.jar;
                C:\Program Files\Java\jdk1.6.0_20\jre\lib\ext\dnsns.jar;
                C:\Program Files\Java\jdk1.6.0_20\jre\lib\ext\localedata.jar;
                C:\Program Files\Java\jdk1.6.0_20\jre\lib\ext\sunjce_provider.jar;
                D:\source\APPS\MyApplication\env\lib\activation.jar;
                D:\source\APPS\MyApplication\env\lib\com.ibm.mq.jar;
                D:\source\APPS\MyApplication\env\lib\cryptix-jce-api.jar;
                D:\source\APPS\MyApplication\env\lib\cryptix-jce-provider.jar;
                D:\source\APPS\MyApplication\env\lib\gnu-regexp-1.1.4.jar;
                D:\source\APPS\MyApplication\env\lib\j2ee.jar;
                D:\source\APPS\MyApplication\env\lib\jdom.jar;
                D:\source\APPS\MyApplication\env\lib\jndi.jar;
                D:\source\APPS\MyApplication\env\lib\jnet.jar;
                D:\source\APPS\MyApplication\env\lib\jSNMP.jar;
                D:\source\APPS\MyApplication\env\lib\jsse.jar;
                D:\source\APPS\MyApplication\env\lib\junit.jar;
                D:\source\APPS\MyApplication\env\lib\log4j-1.2.8.jar;
                D:\source\APPS\MyApplication\env\lib\mail.jar;
                D:\source\APPS\MyApplication\env\lib\ojdbc14_10_2.jar;
                D:\source\APPS\MyApplication\env\lib\xalan.jar;
                D:\source\APPS\MyApplication\env\lib\xerces.jar" 
    com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter 
    -ideVersion5 tests.ValidationUtilsTest

If I open up my Junit jar file that I'm using, under junit/textui I only have a class called TestRunner. This makes me think IntelliJ is trying to use the wrong version (i.e., not 3.7)

What can I try? I've Googled this but haven't had much luck

Jimmy
  • 16,123
  • 39
  • 133
  • 213
  • 1
    Did you try to locate JAR files containing the class `junit/textui/ResultPrinter` in your workspace? You can use a tool such as [ClassFinder](http://www.adarshr.com/papers/classfinder) for this. – adarshr Mar 08 '11 at 12:31

1 Answers1

12

IntelliJ IDEA doesn't support JUnit 3.7. The minimum supported version is 3.8. Update your JUnit jar in the classpath and everything will be fine.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • 1
    Many verions of Android don't have support JUnit 3.8, is there any way to use 3.7 in IntelliJ IDEA ? – xordon Jul 22 '11 at 09:28
  • You can add 3.8 in the classpath so that it appears before 3.7 provided by Android. – CrazyCoder Jul 22 '11 at 17:19
  • I'm using IDEA 11 where this problem occurs for android development for me too. I downloaded junit 3.8.1 and putted it in my test project as dependency. moved it up before android as recommended. But now I'm getting 'JUnit version 3.8 or later expected: java.lang.RuntimeException: Stub!' There is a question here on SO for that but the answer doesn't help too: http://stackoverflow.com/a/2431427/194609 Any pointers? – Karussell Jan 16 '12 at 11:37
  • Create a new question with the sample project and the steps to reproduce or contact support for help. – CrazyCoder Jan 16 '12 at 16:42
  • 2
    details on how to add junit.jar in the classpath? There's a lot of config dialogs and gradle files... – AlexChaffee Jun 06 '14 at 21:24