我正在继承一个项目。我最近更新了Proguard和Junit版本,并且正在运行命令ant jtest
的问题。
我目前拥有的软件版本:
Java 1.8.0_141
ant 1.10.1
proguard:最近更新为5.3.3,为4.9
junit:最近更新为4.12,为4.10
测试套件在Eclipse中运行良好,但是当用命令从Cygwin跑步时,我会在输出结束时获得此错误:
jtest:
[mkdir] Created dir: C:usersuserDocumentsWorkspaceprojectbuildtest-data
[echo]
[junit] Testsuite: com.package.project.AllTests
[junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.016 sec
[junit]
[junit] Testcase: initializationError took 0.002 sec
[junit] 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.defineClass(ClassLoader.java:763)
[junit] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[junit] at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
[junit] at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
[junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
[junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
[junit] at java.security.AccessController.doPrivileged(Native Method)
[junit] at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[junit] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[junit] at java.lang.Class.getDeclaredConstructors0(Native Method)
[junit] at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
[junit] at java.lang.Class.getConstructor0(Class.java:3075)
[junit] at java.lang.Class.getConstructor(Class.java:1825)
[junit] at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[junit] Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
[junit] at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[junit] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[junit]
这是我的build.xml文件
我对build.xml文件并不熟悉。我知道此错误是因为Junit具有Hamcrest-Core-1.3.jar的依赖性。我如何将junit指向hamcrest-core-1.3.jar文件以使此命令起作用?我可以从build.xml吗?
您的jtest
目标使用此classPath运行junit
:
<path id="test.classpath">
<pathelement location="${testclassesdir}" />
<pathelement location="${builddir}/project.jar" />
<path refid="project.libs" />
<pathelement location="${toolsdir}/junit4.12/junit-4.12.jar" />
</path>
您需要将hamcrest-core-1.3.jar添加到该类路径。您可以通过为${toolsdir}
创建目录名称" Hamcrest1.3"并将hamcrest-core-1.3.jar
下载到该目录中,然后更新test.classpath
以添加此pathelement
:
<pathelement location="${toolsdir}/hamcrest1.3/hamcrest-core-1.3.jar" />