运行所有的单元测试Ant构建器 [英] 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:
<一个href=\"http://ant.apache.org/manual/Tasks/junit.html\">http://ant.apache.org/manual/Tasks/junit.html
这篇关于运行所有的单元测试Ant构建器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!