又一个Ant + JUnit类路径问题

DeX*_*eX3 5 java eclipse ant junit classpath

我正在使用Eclipse开发Eclipse SWT应用程序.还有一些JUnit 4测试,测试一些DAO.但是当我尝试通过ant构建运行测试时,所有测试都失败了,因为找不到测试类.

谷歌带来了大约一百万人都有同样的问题,但他们的解决方案似乎都不适合我 - .-.

这些是我的build.xml文件的内容:

<property name="test.reports" value="./test/reports" />
<property name="classes" value="build" />


<path id="project.classpath">
    <pathelement location="${classes}" />
</path>

<target name="testreport">
    <mkdir dir="${test.reports}" />
    <junit fork="yes" printsummary="no" haltonfailure="no">
        <batchtest fork="yes" todir="${test.reports}" >
            <fileset dir="${classes}">
                <include name="**/Test*.class" />
            </fileset>
        </batchtest>
        <formatter type="xml" />

        <classpath refid="project.classpath" />


    </junit>

    <junitreport todir="${test.reports}">
        <fileset dir="${test.reports}">
            <include name="TEST-*.xml" />
        </fileset>
        <report todir="${test.reports}" />
    </junitreport>
</target>
Run Code Online (Sandbox Code Playgroud)

测试类与应用程序类一起位于build-directory中,尽管它们根据其包在某些子文件夹中.

也许这也很重要:首先,Ant抱怨JUnit不在其类路径中,但是因为我把它放在那里(使用eclipse配置编辑器),它抱怨JUnit在其类路径中两次.

WARNING: multiple versions of ant detected in path for junit 
   [junit]          jar:file:C:/Users/as df/Documents/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib/ant.jar!/org/apache/tools/ant/Project.class
   [junit]      and jar:file:/C:/Users/as%20df/Documents/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib/ant.jar!/org/apache/tools/ant/Project.class
Run Code Online (Sandbox Code Playgroud)

我已经尝试指定每个子目录,每个类文件,我已经尝试过文件集和文件列表,似乎没什么用.

谢谢你的帮助,我现在已经在这件事上坐了好几个小时......

Dro*_*roj 6

我只是在对junit任务使用'fork = true'选项时才得到这个.这是因为我的ANT_HOME中有'..'(例如'/3rdparth/jboss/jboss-5/../tools').一旦我减少了这条道路,'蚂蚁'的多个版本就会消失.


小智 3

我遇到了同样的问题“在 junit 的路径中检测到多个版本的 ant”。当我重命名 Eclipse_Home 目录并从中删除特殊字符时,问题就消失了。该路径中有“[1]”,这导致了问题。