如何 运行 在带有参数的 ant 中进行特定的 junit 测试?

How to run a specific junit test in ant with parameter?

首先,我在Whosebug上搜索了一下,以下问题与我的相关,但不完全是我想要的:

假设我有超过 100 个测试用例:A1Test...A100Test。我可以将 ant 中的 junit bachtest 制作成 运行 全部。但我只想运行,比方说,A50Test。我如何配置我的 build.xml,以便我可以 运行:

ant test A50Test

我不想为每个测试创建 100 个目标。

引入属性定义你要执行的测试名称:

<property name="unit.test" value="*.java" />

在你的批测试中使用这个属性:

<batchtest fork="yes" todir="${output.test.dir}">
    <fileset dir="${source.test.dir}" includes="**/${unit.test}"/>
</batchtest>

将此 属性 的值传递给 ant:

ant test -Dunit.test=A50Test

但在我的例子中,我需要在 ${unit.test} 的末尾添加“.java”使其生效。
希望能帮助别人。 ^^

<batchtest fork="yes" todir="${output.test.dir}">
    <fileset dir="${source.test.dir}" includes="**/${unit.test}.java"/>
</batchtest>