[英]Junit tests wont run using ant
我已经能够使用ant成功编译并运行该项目。 但是,当我尝试运行测试文件时,它给了我一个奇怪的Reference ./lib/junit-4.11.jar。 我在junit任务中不得不提到的提法中可能做错了什么。 请指出错误。
<target name="clean">
<delete dir="build"/>
</target>
<target name="compile">
<mkdir dir="build/classes"/>
<javac srcdir="./src/com/twu/biblioteca/" destdir="build/classes"/>
</target>
<target name="jar">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/Application.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="com.twu.biblioteca.Application"/>
</manifest>
</jar>
</target>
<target name="run">
<java jar="build/jar/Application.jar" fork="true"/>
</target>
<target name="junit" depends="compile">
<junit printsummary="yes" haltonfailure="no">
<!-- Project classpath, must include junit.jar -->
<classpath refid="./lib/junit-4.11.jar" />
<!-- test class -->
<classpath location="./test/BooksController" />
<test name="com.twu.biblioteca.BooksControllerTest"
haltonfailure="no" todir="./report">
<formatter type="plain" />
<formatter type="xml" />
</test>
</junit>
</target>
问题出在您的junit classpath元素上。 refid属性允许您引用预定义的引用,并且ant通知您没有此类引用。 另外,在junit任务下您应该只具有一个classpath元素(它可以与多个元素一起使用,但是文档仅支持一个)。
删除那些classpath元素并替换为
<classpath>
<pathelement location="lib/junit-4.11.jar"/>
<pathelement location="test/BooksController"/>
</classpath>
它应该工作。 在这里,我们通过将junit jar添加到路径,然后添加包含测试的目录来构建类路径。 您可能还必须将您的主类添加到该类中 ,并使用另一个路径指定它们的位置。
有关这些类似路径的结构的更多信息,请参见ant文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.