Junit ant task - JUnitTask was not found

徘徊边缘 提交于 2020-01-01 05:02:29

问题


I'm trying to run Junit test from my ant build.xml file. I read here that you can use a junit.jar file instead of using the .jar that is located in the ant.home/lib directory. This is what I want to do since our Jenkins autobuild set-up has no junit.jar file in his ant lib directory.

Even with the simpliest project, I'm always getting this error that the JUnitTask was not found. If you look at my build.xml file, it is clearly included and used in the junit task.

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>

The small example I made to test things out looks like this :

EDIT : Updated based on answer


回答1:


The junit-Documentation is a bit sparse.
If you have ant-junit.jar outside ANT_HOME/lib you need to define the task yourself (the <taskdef/> is from the FAQ, which is also a bit wrong, because it tells to use class="...", which does not exist as an attribute to <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>

This can be used to check the path:

<pathconvert  property="testoutput" refid="classpath.test"/>
<echo>Path = ${testoutput}</echo>

Documentation:
junit task.


Additional information can be found in this chat transcript




回答2:


My solution is create a CLASSPATH variable in Jenkins System Configure, and add the ant-junit.jar path




回答3:


found this elsewhere...

(using Mint, based on Debian)

sudo apt-get install ant-optional


来源:https://stackoverflow.com/questions/9774264/junit-ant-task-junittask-was-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!