Junit的Ant任务 - JUnitTask没有被发现 [英] Junit ant task - JUnitTask was not found

查看:451
本文介绍了Junit的Ant任务 - JUnitTask没有被发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的Ant build.xml文件运行JUnit测试。我读 中,你可以使用的junit.jar文件,而不是使用的。罐子是位于ant.home / lib目录中。这是我想做的事情,因为我们的詹金斯自动构建建立在他的蚂蚁lib目录中没有的junit.jar文件。

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.

即使有simpliest项目,我总是得到这个错误的JUnitTask没有被发现。如果你看一下我的build.xml文件,明确列入,并在junit任务使用。

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文件:

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 :

编辑:更新基于答案

推荐答案

JUnit的-文档是有点稀疏。结果
如果你有外 ANT_HOME /蚂蚁的junit.jar LIB 你需要自己(的&LT定义任务;的taskdef /&GT; 常见问题解答,这也是有点不对劲,因为它告诉使用类=...,不存在以℃的属性;的taskdef /&GT;

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>

这可用于检查路径

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

文件:结果
junit任务

其他信息可以在此聊天记录

这篇关于Junit的Ant任务 - JUnitTask没有被发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆