[英]Ant Junit testing puttering out - need the summary
我正在使用ant来构建我的java程序。 它可以正常编译,但是当我运行单元测试类时,找不到类文件。 我把我的类路径弄得一团糟,这个异常不断出现吗?
lib中的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.jar
和hamcrest-all-XXjar添加到您的类路径中。
具体来说,您需要在lib文件夹中使用hamcrest-core-1.3.jar
(对于jUnit 4.11)。
请按照以下步骤操作:
Build Path
然后从其菜单中选择“ Add Libraries
。 JUnit
然后单击Next。 JUnit4
然后选择Finish。 和
如果UPDATE1不起作用,
您可以下载JUnit 4.7
并将junit-4.7.jar
放在构建路径中(而不是旧版本)。 那可以解决你的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.