我注意到Junit批测试允许重写Junit的forkmode参数。这很好。
然而,进一步检查——batchtest似乎不支持"forkmode"标志?
这似乎很奇怪。这意味着被覆盖的选项不具有与junit分支选项相同的功能。
这是故意的吗?如果是,为什么?
根据JUnit Ant任务文档,您不能在batchtest中重写forkmode参数。
通常你会这样使用forkmode选项:
<junit printsummary="yes"
fork="yes" forkmode="perBatch"
haltonfailure="${halt.on.test.failure}"
failureproperty="test.failed">
<classpath refid="test.classpath"/>
<syspropertyset refid="junit.properties"/>
<jvmarg value="${test.locale}"/>
<jvmarg value="-Xmx256M"/>
<formatter type="plain"/>
<batchtest todir="${reports.test}">
<fileset dir="${src.test}">
<include name="**/Test*.java"/>
<exclude name="**/AllTests.java"/>
</fileset>
</batchtest>
</junit>
其中forkmode可以是"once", "perTest"或"perBatch"
"perBatch"选项用于为每个嵌套的<batchtest>
创建一个VM。如果您在<batchtest>
中覆盖<junit>
的"fork",则您将在单个VM中运行测试。
在<batchtest>
元素中增加"forkmode"选项是没有意义的。您可以在junit元素中控制VM的"分叉"模式。