我对Ant不太满意,但我们将它用作构建工具.现在,我们可以运行"蚂蚁测试",它将贯穿所有单元测试.
但是,我希望能够做一些类似的事情ant test some_module
并让它some_module
作为参数接受,并且只测试它.
我一直无法找到如何将命令行参数传递给Ant - 任何想法?
mar*_*ton 38
一种解决方案可能如下.(我有一个项目可以做到这一点.)
有类似于一个个独立的目标test
与fileset
制约的测试只有一个类.然后-D
在ant命令行中使用该类的名称:
ant -Dtest.module=MyClassUnderTest single_test
Run Code Online (Sandbox Code Playgroud)
在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>
Run Code Online (Sandbox Code Playgroud)
您还可以使用可选的默认值定义属性,该默认值可以通过命令行替换,例如
<target name="test">
<property name="moduleName" value="default-module" />
<echo message="Testing Module: ${moduleName}"/>
....
</target>
Run Code Online (Sandbox Code Playgroud)
并运行它:
ant test -DmoduleName=ModuleX
Run Code Online (Sandbox Code Playgroud)
如何在测试目标中使用一些条件并指定-Dcondition=true
?
<target name="test" depends="_test, _test_if_true>
...
</target>
<target name="_test_if_true" if="condition">
...
</target>
<target name="_test" unless="condition">
...
</target>
Run Code Online (Sandbox Code Playgroud)
从ant faq改编了一下.
您可以在调用 ant 时在命令行上定义一个属性:
ant -Dtest.module=mymodulename
Run Code Online (Sandbox Code Playgroud)
然后你可以将它用作任何其他 ant 属性:
...
<fileset dir="${test.dir}" includes="**/${test.module}.class" />
...
Run Code Online (Sandbox Code Playgroud)
看一下Ant 的手册。
归档时间: |
|
查看次数: |
56458 次 |
最近记录: |