我正在尝试使用在Eclipse IDE中插入Ant的JUnit来测试几个单元。我收到了以下错误。
test:
[junit] Testsuite: TestMessageUtil
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.004 sec
[junit] Testcase: initializationError(TestMessageUtil): Caused an ERROR
[junit] org/hamcrest/SelfDescribing
[junit] java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
[junit] at java.lang.ClassLoader.defineClass1(Native Method)
[junit] at java.lang.ClassLoader.defineClassCond(Unknown Source)
[junit] at java.lang.ClassLoader.defineClass(Unknown Source)
[junit] at java.security.SecureClassLoader.defineClass(Unknown Source)
[junit] at java.net.URLClassLoader.defineClass(Unknown Source)
[junit] at java.net.URLClassLoader.access$000(Unknown Source)
[junit] at java.net.URLClassLoader$1.run(Unknown Source)
[junit] at java.security.AccessController.doPrivileged(Native Method)
[junit] at java.net.URLClassLoader.findClass(Unknown Source)
[junit] at sun.misc.Launcher$ExtClassLoader.findClass(Unknown Source)
[junit] at java.lang.ClassLoader.loadClass(Unknown Source)
[junit] at java.lang.ClassLoader.loadClass(Unknown Source)
[junit] at java.lang.reflect.Constructor.newInstance(Unknown Source)
[junit] at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[junit] at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
[junit] at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
[junit] Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
[junit] at java.net.URLClassLoader$1.run(Unknown Source)
[junit] at java.security.AccessController.doPrivileged(Native Method)
[junit] at java.net.URLClassLoader.findClass(Unknown Source)
[junit] at sun.misc.Launcher$ExtClassLoader.findClass(Unknown Source)
[junit] at java.lang.ClassLoader.loadClass(Unknown Source)
[junit] at java.lang.ClassLoader.loadClass(Unknown Source)
[junit] Test TestMessageUtil FAILED
BUILD SUCCESSFUL
请帮忙。我知道我必须在我的类路径中包含hamcrest.jar。但是从哪里可以找到那个jar文件?
答案 0 :(得分:1)
其中dependency.lib指向包含所需jar的文件夹
<path id="compile.classpath">
<fileset dir="${dependecies.lib}">
<include name="*.jar" />
</fileset>
</path>
答案 1 :(得分:1)
您似乎在运行时遇到问题,因此请更改其类路径的配置:
hamcrest-core-1.3.jar
作为外部jar