使用Ant构建器运行所有单元测试 [英] Run all unit tests with Ant builder
问题描述
< target name =MyTest>
< mkdir dir =$ {junit.output.dir}/>
< junit fork =yesprintsummary =withOutAndErr>
< formatter type =xml/>
< test name =tests.MyTesttodir =$ {junit.output.dir}/>
< classpath refid =MyProject.classpath/>
< / junit>
< / target>
此方法需要我每次添加单元测试时更改构建文件。
我想能够使用单个Ant构建器目标在项目中运行所有单元测试。
可以做吗?
是的,您需要查看文件集标签,例如: / p>
< junit printsummary =yeshaltonfailure =yes>
< classpath>
< pathelement location =$ {build.tests}/>
< pathelement path =$ {MyProject.classpath}/>
< / classpath>
< formatter type =xml/>
< batchtest fork =yestodir =$ {reports.tests}>
< fileset dir =$ {src.tests}>
< include name =** / * Test * .java/>
< exclude name =** / AllTests.java/>
< / fileset>
< / batchtest>
< / junit>
重要的部分是使用文件集和glob /通配符模式来匹配测试的名称。关于junit任务的完整文档,请参见以下示例:
http://ant.apache.org/manual/Tasks/junit.html
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>
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>
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构建器运行所有单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!