【发布时间】:2016-06-15 15:54:09
【问题描述】:
我正在使用 ant 构建我的 java 程序。它编译得很好,但是当我去运行单元测试类时,它找不到类文件。我已经把我的类路径搞砸了,而且这个异常不断出现?
lib中的jar如下:
- ant.jar
- hamcrest.jar
- hamcrest-core-1.3.jar
- hamcrest-all-1.3.jar
- hamcrest-core.jar
- junit.jar
构建文件build.xml:
<project name="PillarWorkspaceHiring" default="test" basedir=".">
<description>
Author: April Randolph for a evening of babysitting. Uses Ant to build the junit, hamcrest java program.
Babysitting Kata
</description>
<!-- Set global properties for this build -->
<property name="test.src.dir" value="src/main/java"/>
<property name="test.build.dir" value="build/test"/>
<property name="main.build.dir" value="build/main"/>
<property name="main.src.dir" value="src/main/java"/>
<property name="full-compile" value="true"/>
<target name="clean" description="clean up">
<!-- Delete the ${dir.build} -->
<delete verbose="${full-compile}" >
<fileset dir="${main.build.dir}" includes="**/*.class" />
<fileset dir="${test.build.dir}" includes="**/*.class" />
</delete>
</target >
<path id="classpath.test">
<pathelement location="lib/junit-4.12.jar"/>
<pathelement location="lib/hamcrest-core-1.3.jar"/>
<pathelement location="lib/ant.jar"/>
<pathelement location="${main.build.dir}"/>
</path>
<!-- Testsuite-->
<target name="test" depends="test-compile" >
<junit printsummary="on" haltonfailure="yes" fork="true">
<classpath>
<path refid="classpath.test"/>
<pathelement location="${test.build.dir}"/>
</classpath>
<formatter type="brief" usefile="false" />
<batchtest>
<fileset dir="${test.src.dir}" includes="**/*Test*.java" />
</batchtest>
</junit>
</target>
<!-- Build main class files -->
<target name="compile" >
<mkdir dir="${main.build.dir}"/>
<javac srcdir="${main.src.dir}" destdir="${main.build.dir}" includeantruntime="false">
<classpath refid="classpath.test"/>
</javac>
</target>
<target name="test-compile" depends="compile">
<mkdir dir="${test.build.dir}"/>
<javac srcdir="${test.src.dir}" destdir="${test.build.dir}" includeantruntime="false">
<classpath refid="classpath.test"/>
</javac>
</target>
</project>
膨胀:hamcrest\SelfDescribing.class
我从控制台得到这个
test:
我做错了什么?
【问题讨论】:
-
您使用哪个版本的 JUnit?
-
@Stefan 原来我以某种方式卸载了我需要的一个框架,这就是我的问题。现在我得到了一切成功,尽管测试:只显示了这一点。 (更新了问题)
-
从类路径中删除
lib/ant.jar。 -
@stefanBirkner 仍然没有输出来验证我的测试套件发生了什么。