无法在旧版本的 JUnit 上运行简单的 JUnit TestCase
我正在尝试在 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 以及声明它支持 3.x 和 4.x 的 IntelliJ 插件
我可以看到 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)
我可以尝试什么?我用谷歌搜索过这个,但运气不佳
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IntelliJ IDEA 不支持 JUnit 3.7。支持的最低版本是3.8。更新类路径中的 JUnit jar,一切都会好起来的。
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.