我对 Ant 不太擅长,但我们将它用作构建工具。现在,我们可以运行“ Ant 测试”,它将运行所有单元测试。
但是,我希望能够做类似 ant test some_module
的事情。并让它接受 some_module
作为参数,并且只测试它。
我一直无法找到如何将命令行参数传递给 Ant - 有什么想法吗?
最佳答案
一种解决方案可能如下。 (我有一个项目可以做到这一点。)
有一个类似于 test
的单独目标与 fileset
将测试限制为仅一类。然后使用 -D
传递该类的名称在 Ant 命令行:
ant -Dtest.module=MyClassUnderTest single_test
在 build.xml (高度减少)中:
<target name="single_test" depends="compile" description="Run one unit test">
<junit>
<batchtest>
<fileset dir="${test.dir}" includes="**/${test.module}.class" />
</batchtest>
</junit>
</target>
关于ant - 如何将参数传递给 Ant 任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1911536/