另一个 Ant + JUnit 类路径问题 [英] Yet another Ant + JUnit classpath problem

查看:34
本文介绍了另一个 Ant + JUnit 类路径问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm developing an Eclipse SWT application using Eclipse. There are also some JUnit 4 tests, which test some DAO's. But when I try to run the tests via an ant build, all of the tests fail, because the test classes aren't found.

Google 提出了大约 100 万个都有同样问题的人,但他们的解决方案似乎都不适合我 -.- .

Google brought up about a million of people who all have the same problem, but none of their solutions seem to work for me -.- .

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

These are the contents of my build.xml file:

<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>

测试类与应用程序类一起位于构建目录中,尽管它们根据其包位于一些子文件夹中.

The test classes are in the build-directory together with the application classes, although they are in some subfolders according to their packages.

也许这也很重要:起初 Ant 抱怨 JUnit 不在它的类路径中,但是自从我把它放在那里(使用 eclipse 配置编辑器)它抱怨 JUnit 两次出现在它的类路径中.

Maybe this is important too: At first Ant complained that JUnit wasn't in its classpath, but since I put it there (with the eclipse configuration editor) it complains about JUnit being in its classpath twice.

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

我试过指定每一个子目录、每一个类文件,我试过文件集和文件列表,但似乎没有任何效果.

I've tried specifying each and every subdirectory, each and every class file, I've tried filesets and filelists, nothing seems to work.

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

Thanks for your help, I've been sitting for hours on this thing now...

推荐答案

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

I had the same problem 'multiple versions of ant detected in path for junit'. The problem went away when I renamed by Eclipse_Home directory and removed special characters from it. The path had '[1]' in it which was causing the problem.

这篇关于另一个 Ant + JUnit 类路径问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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