我正在尝试在JUnit的3.7版本上运行一个简单的JUnit测试用例(我无法将其升级到最新版本)
运行IntelliJ,当我尝试运行JUnit测试用例时,我收到以下异常:
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
我的类路径上有IntelliJ版本10.0.2,JUnit 3.7和IntelliJ插件,表明它支持3.x和4.x
我可以看到IntelliJ执行以下操作(添加了中断以使其更具可读性)
"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
如果我打开我正在使用的Junit jar文件,在junit / textui下我只有一个名为TestRunner的类。这让我觉得IntelliJ试图使用错误的版本(即不是3.7)
我可以尝试什么?我用Google搜索了这个,但没有太多运气
答案 0 :(得分:12)
IntelliJ IDEA不支持JUnit 3.7。支持的最低版本为 3.8 。在类路径中更新你的JUnit jar,一切都会好的。