Junit ant任务 – 找不到JUnitTask
发布时间:2020-12-14 05:48:45 所属栏目:Java 来源:网络整理
导读:我正在尝试从我的ant build.xml文件运行Junit测试.我读了 here,你可以使用junit.jar文件而不是使用位于ant.home / lib目录中的.jar.这是我想要做的,因为我们的Jenkins autobuild设置在他的ant lib目录中没有junit.jar文件. 即使使用最简单的项目,我总是会收
我正在尝试从我的ant build.xml文件运行Junit测试.我读了
here,你可以使用junit.jar文件而不是使用位于ant.home / lib目录中的.jar.这是我想要做的,因为我们的Jenkins autobuild设置在他的ant lib目录中没有junit.jar文件.
即使使用最简单的项目,我总是会收到JUnitTask未找到的错误.如果你查看我的build.xml文件,它显然包含在junit任务中并用于它. build.xml: <project default="all"> <property name="TALK" value="false" /> <path id="classpath.base"> </path> <path id="classpath.test"> <fileset dir="." includes="**/*.jar" /> </path> <target name="compile-test"> <javac srcdir="src" verbose="${TALK}"> <classpath refid="classpath.test" /> </javac> </target> <target name="test" depends="compile-test"> <junit> <classpath refid="classpath.test" /> <formatter type="brief" usefile="false" /> <test name="TestClass" /> </junit> </target> <target name="all" depends="test" /> </project> 我用来测试的小例子看起来像这样: 编辑:根据答案更新 解决方法
junit-Documentation有点稀疏.
如果在ANT_HOME / lib之外有ant-junit.jar,你需要自己定义任务(< taskdef />来自 FAQ,这也有点不对,因为它告诉使用class =“… “,它不作为< taskdef />的属性存在:): <path id="classpath.test"> <fileset dir="." includes="*junit.jar" /> </path> <taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"> <classpath refid="classpath.test"/> </taskdef> 这可以用来检查路径: <pathconvert property="testoutput" refid="classpath.test"/> <echo>Path = ${testoutput}</echo> 文档: 其他信息可在this chat transcript中找到 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |