在 ant junit 任务中更改工作目录 [英] Change working directory in ant junit task

查看:24
本文介绍了在 ant junit 任务中更改工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行 JUnits 测试的 ant 文件.这些测试依赖于某些配置文件的相对路径.我尝试设置批处理测试的工作目录,但失败了.

I have a ant file that runs JUnits tests. These tests rely on a relative path to certain configuration files. I've tried to set the working directory for the batch test, but fail.

我希望工作目录为 ${plugins.dir}/${name}

ant 脚本的 JUnit 部分:

The JUnit part of the ant script:

<junit haltonfailure="no" printsummary="on" fork="true" showoutput="true" dir="${plugins.dir}/${name}">
    <jvmarg value="-Duser.dir=${plugins.dir}/${name}"/>
    <classpath> 
        <path refid="project.classpath"/>
        <pathelement location="${plugins.dir}/${dependency}/@dot/"/>
        <pathelement location="${plugins.dir}/${name}/" />
    </classpath>
    <formatter type="xml" />
    <sysproperty key="basedir" value="${plugins.dir}/${name}"/>
    <sysproperty key="dir" value="${plugins.dir}/${name}"/>
    <batchtest todir="${junit.output}">
        <fileset dir="${dir}"> 
            <include name="**\*AllTests.class" />
        </fileset>
    </batchtest>
</junit>

我用谷歌搜索过,但我发现的解决方法是设置dir"、sysproperty"或jvmarg".正如你所看到的,我都试过了:)

I've googled and searched but the workarounds I've found have been to set the "dir", "sysproperty" or "jvmarg". As you can see I've tried them all :)

有没有办法在标签中打印当前目录?它不支持 .这将允许我验证目录是否实际更改以及更改为什么.

Is there a way to print the current dir in the tag? It doesnt support . That would allow me to verify if the dir is actually changed and to what.

这个等式中的一个通配符是,这是在 Hudson 中运行的,它启动了一个启动 antrunner 的 eclipse 进程.这样我们就可以同时运行 junit 和 eclipse 插件 junit 测试.应该与我认为的问题没有任何关系.

One wildcard in this equation is that this is being run in Hudson that starts upp an eclipse process that starts antrunner. This is so we can run both junit and eclipse plugin junit tests. Shouldn't have anything to do with the problem I think.

推荐答案

我认为您设置 basedir 属性是正确的(请参阅 项目属性).但是,由于它是 ANT(而不是 JVM)的属性,因此它是只读的!

I think you are right with setting the basedir property (see projects attributes). However, since it is a property of ANT (and not of the JVM) it is READ ONLY!

如果你在调用你的 ant 任务时设置了 basedir 会影响其他目标吗?请参阅命令行参考.

Does it effect other target if you set the basedir when calling your ant task? See Command Line reference.

ant -Dbasedir=somedir

或者,跨越一个新的 ant 进程来调用您的 junit 目标.请参阅 AntCall 任务Ant 任务.以下示例假定 junit 目标包含您的 junit 任务.我将此任务用于其他属性(到目前为止从未需要 basedir 属性.

Alternatively, span a new ant process to call your junit target. See the AntCall task or Ant task. Following examples assumes that the junit target contains your junit task. I used this task for other properties (never needed the basedir property so far.

<antcall target="junit">
  <param name="basedir" value="${plugins.dir}/${name}"/>
</antcall>

<ant dir="${plugins.dir}/${name}" target="junit" />

这篇关于在 ant junit 任务中更改工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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