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



所以我有类似的东西

<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(JUnit的c.f.ant文档):

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

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

最新更新