Junit ant任务 – 找不到JUnitTask

前端之家收集整理的这篇文章主要介绍了Junit ant任务 – 找不到JUnitTask前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试从我的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>

文档:
junit task.

其他信息可在this chat transcript中找到

原文链接:https://www.f2er.com/java/121277.html

猜你在找的Java相关文章