无法在旧版本的JUnit上运行简单的JUnit TestCase [英] Unable to run simple JUnit TestCase on old version of JUnit

查看:158
本文介绍了无法在旧版本的JUnit上运行简单的JUnit TestCase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在JUnit 3.7版本上运行一个简单的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)

运行IntelliJ ,当我尝试运行我的JUnit测试用例时,我得到以下异常:

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

我的类路径上有IntelliJ版本10.0.2,JUnit 3.7和IntelliJ插件,表明它支持3.x和4.x

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

我可以看到IntelliJ执行以下操作(添加了中断以使其更具可读性)

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

如果我打开我的Junit jar文件我正在使用,在junit / textui下我只有一个名为TestRunner的类。这让我觉得IntelliJ试图使用错误的版本(即不是3.7)

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)

我可以尝试一下吗?我已经用Google搜索过但运气不好

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

推荐答案

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.

这篇关于无法在旧版本的JUnit上运行简单的JUnit TestCase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆