使用 Ant builder 运行所有单元测试 [英] Run all unit tests with Ant builder
问题描述
我的项目中有一个包含一堆 JUnit 测试的目录.到目前为止,我为每个单元测试使用了单独的目标.例如:
I have a directory with a bunch of JUnit tests in my project. So far I have used separate target for each unit test. For example:
<target name="MyTest">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="tests.MyTest" todir="${junit.output.dir}"/>
<classpath refid="MyProject.classpath"/>
</junit>
</target>
此方法要求我每次添加单元测试时更改构建文件.
我希望能够使用单个 Ant 构建器目标运行项目中的所有单元测试.
可以吗?
This method requires me to change build file every time I add a Unit test.
I want to able able to to run all unit tests in the project with a single Ant builder target.
Is it possible to do?
推荐答案
是的,您需要查看文件集标签,例如:
Yep it is, you need to look at the fileset tag, e.g:
<junit printsummary="yes" haltonfailure="yes">
<classpath>
<pathelement location="${build.tests}"/>
<pathelement path="${MyProject.classpath}"/>
</classpath>
<formatter type="xml"/>
<batchtest fork="yes" todir="${reports.tests}">
<fileset dir="${src.tests}">
<include name="**/*Test*.java"/>
<exclude name="**/AllTests.java"/>
</fileset>
</batchtest>
</junit>
重要的部分是使用文件集和通配符/通配符模式来匹配测试的名称.有关 junit 任务的完整文档和示例:
The important part is the use of fileset and a glob/wildcard pattern to match the names of the tests. Full docs on the junit task with examples here:
http://ant.apache.org/manual/Tasks/junit.html
这篇关于使用 Ant builder 运行所有单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!