使用Ant构建器运行所有单元测试 [英] Run all unit tests with Ant builder

查看:103
本文介绍了使用Ant构建器运行所有单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个JUnit测试的目录。到目前为止,我已经为每个单元测试使用单独的目标。例如:

 < 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆