蚂蚁类路径和的junit.jar [英] Ant classpath and junit.jar

查看:330
本文介绍了蚂蚁类路径和的junit.jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个build.xml文件,允许我运行JUnit测试。下面是相关的部分:

I have the an build.xml that allows me to run junit tests. Here is the relevant part:

<path id="JUnit 4.libraryclasspath">
    <pathelement location="../../../../../eclipse/plugins/org.junit4_4.5.0.v20090824/junit.jar"/>
    <pathelement location="../../../../../eclipse/plugins/org.hamcrest.core_1.1.0.v20090501071000.jar"/>
</path>
<path id="MyProject.classpath">
    <pathelement location="bin"/>
    <path refid="JUnit 4.libraryclasspath"/>
</path>

<target name="run_unit_tests" depends="build">
        <mkdir dir="${junit.output.dir}"/>
        <junit printsummary="yes" haltonfailure="no">   
            <classpath refid="MyProject.classpath" />

            <formatter type="xml"/>
            <batchtest todir="${junit.output.dir}">
                    <fileset dir="${src}">
                            <include name="**/*Test*.java"/>
                    </fileset>
            </batchtest>
        </junit>
</target>

如果我更换行:

<pathelement location="../../../../../eclipse/plugins/org.junit4_4.5.0.v20090824/junit.jar"/>

<pathelement location="${eclipse.home}/plugins/org.junit4_4.5.0.v20090824/junit.jar"/>

的变化打破了类路径。我收到以下错误:

The change breaks the classpath. I get the following error:

&LT;&类路径GT; &LT;&JUnit的GT; 必须
  如果不是在蚂蚁自身包括的junit.jar
  类路径

The <classpath> for <junit> must include junit.jar if not in Ant's own classpath

据我了解,位置属性应该保持在这两种情况下相同的值。那么什么可以是什么原因呢?

As far as I understand, the location attribute should hold the same value in both cases. So what can be the reason?

作为一个方面的问题,这个版本的文件不会对不同JUnit版本(路径将打破)的环境中工作。是否有可能增加一个一般路径的junit.jar?

As a side question, this build file will not work on an environment with different junit version (the path will break). Is it possible to add a "general" path to junit.jar?

推荐答案

JUnit类库所在的地方你告诉它驻留。就个人而言,我会完全忘记了对随Eclipse中jar文件链接,而是下载的罐子直接的。

The JUnit library resides wherever you tell it to reside. Personally, I would forget entirely about linking against the jar files shipped with Eclipse and instead download the jars directly.

如果我有一个项目,说在路径 /项目那么我会尝试把依赖某处的层次结构,就像在 /项目/test/lib/junit.jar 。如果我的Ant构建文件然后 /project/build.xml 那么它的加入为简单的 ./测试/ lib中/的junit.jar 来JUnit的类路径。想你的机器上引用的任意位置是脆弱的(记住,Eclipse的可安装的随时随地的),特别是使用相对路径时(因为你的项目内容可以同时存储随时随地的)。

If I have a project, say at path /project then I would try to put the dependency somewhere in that hierarchy, like at /project/test/lib/junit.jar. If my ant build file is then /project/build.xml then it's as simple as adding ./test/lib/junit.jar to the JUnit classpath. Trying to reference an arbitrary location on your machine is fragile (remember, Eclipse could be installed anywhere), particularly when using relative paths (since your project contents could also be stored anywhere).

这篇关于蚂蚁类路径和的junit.jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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