我可以将所有 <jvmarg> 参数从单个文件传递给 ant junit 任务吗

Can I pass all the <jvmarg> parameters to an ant junit task from a single file

所以我有类似的东西

<junit fork="true" forkmode="perTest">
   <jvmarg value="-Darg.to.pass.our.tests.one=arg1">
   <jvmarg value="-Darg.to.pass.our.tests.two=arg2">
   <jvmarg value="-Darg.to.pass.our.tests.three=arg3">
   ...
   <jvmarg value="-Darg.to.pass.our.tests.enn=argN">
</junit>

我知道理想情况是分叉一次,但对于我们的测试来说这是不可能的,原因我将不再赘述。

我的问题是,我可以做类似的事情吗:

<junit fork="true" forkmode="perTest">
   <jvmargs file="standard_args.properties">
</junit>

我正在寻找在测试执行时指定不同参数的自由。

我知道我可以做到

<junit fork="true" forkmode="perTest">
   <jvmarg value="${arg.one}">
   <jvmarg value="${arg.two}">
   ...
   <jvmarg value="${arg.enn}">
</junit>

我确实使用了这种方法,但这对传递的参数的确切数量提出了期望。

有什么想法吗?

因为您传递给测试的所有属性都是系统属性 (-Dxxx=yyy) ,您应该考虑使用 syspropertyset (c.f.ant 文档 JUnit ):

<property file="standard_args.properties"/>
...
<junit fork="true" forkmode="perTest">
    <syspropertyset>
        <propertyref prefix="standard.arg"/>
    </syspropertyset>
</junit>

假设您的 属性 文件 standard_args.properties 包含您的测试属性,并且所有这些属性都以特定模式开头(即上例中的 standard.arg)。