Search code examples
javajunitintellij-ideajunit3

Unable to run simple JUnit TestCase on old version of JUnit


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


Solution

  • 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.