问题描述
我正尝试在 https://github.com/cdwijayarathna/上对我的项目运行简单的单元测试oj4j .
我将junit-4.12.jar和ant-junit4.jar都添加到了lib文件夹中.
I added both junit-4.12.jar and ant-junit4.jar to the lib folder.
但是当我运行"rake run_tests"时,在给出的报告位置出现了以下错误.
But when I ran "rake run_tests", I'm getting following error at the report location I have given.
java.lang.NoClassDefFoundError: junit/framework/JUnit4TestAdapterCache
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:195)
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
这是什么原因?我该怎么解决?
What's the reason for that? how can I solve this?
推荐答案
我在Debian上通过ant通过junit运行junit时遇到了相同的异常.通过在$ CLASSPATH环境变量中包含junit4.jar,我可以使其运行.这意味着jvm没有在junit4.jar上启动. /usr/share/java/junit4.jar
路径特定于Debian的junit软件包,因此您需要适当地替换.
I had the same exception running junit through ant on Debian. By including the junit4.jar in the $CLASSPATH environment variable I was able to get it running. Which means the jvm was not picking up on the junit4.jar. The /usr/share/java/junit4.jar
path is specific to Debian's junit package, so you will need to replace as appropriate.
$ export CLASSPATH=/usr/share/java/junit4.jar
$ ant test
这篇关于junit给出错误java.lang.NoClassDefFoundError:junit/framework/JUnit4TestAdapterCache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!