Ant classpath和junit.jar [英] Ant classpath and junit.jar

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

问题描述

我有一个build.xml允许我运行junit测试。以下是相关部分:

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

< target name =run_unit_testsdepends =build>
< mkdir dir =$ {junit.output.dir}/>
< junit printsummary =yeshaltonfailure =no>
< classpath refid =MyProject.classpath/>

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

如果我替换行:



<$ p / $ / $ / $ / $ / $

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

更改会打破类路径。我收到以下错误:


<$ c $ < classpath> $ c>< junit> 必须
如果没有在Ant的自己的
classpath中包含junit.jar


据我所知,在两种情况下,location属性应该保持相同的值。那么可能是什么原因?



作为一个侧面的问题,这个构建文件将不会在具有不同junit版本的环境(路径将中断)上工作。是否可以为junit.jar添加一般路径?

解决方案

JUnit库驻留在任何地方。就个人而言,我将完全忘记与Eclipse附带的jar文件的链接,而不是直接下载jar文件



如果我有一个项目,在路径 / project 说,那么我会尝试将依赖项放在如 /project/test/lib/junit.jar 。如果我的ant构建文件是 /project/build.xml ,那么就像添加 ./ test / lib / junit.jar 到JUnit类路径。尝试引用机器上的任意位置是脆弱的(请记住,Eclipse可以在任何地方安装),特别是在使用相对路径时(由于您的项目内容可以存储 any


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>

If I replace the line:

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

with

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

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

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?

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?

解决方案

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.

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

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

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