简体   繁体   English

使用Ant构建器运行所有单元测试

[英]Run all unit tests with Ant builder

I have a directory with a bunch of JUnit tests in my project. 我的项目中有一堆JUnit测试的目录。 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. 我希望能够使用单个Ant构建器目标在项目中运行所有单元测试。
Is it possible to do? 有可能吗?

Yep it is, you need to look at the fileset tag, eg: 是的,你需要查看文件集标签,例如:

<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. 重要的部分是使用fileset和glob / wildcard模式来匹配测试的名称。 Full docs on the junit task with examples here: 关于junit任务的完整文档以及示例:

http://ant.apache.org/manual/Tasks/junit.html http://ant.apache.org/manual/Tasks/junit.html

Yep! 是的! We do it using an ant command batchtest. 我们使用ant命令batchtest来完成它。 Looks like this: 看起来像这样:

        <batchtest todir="${junit.report.dir}">
            <fileset dir="${basedir}\test\unit">
                <include name="**/*Test.java" />
            </fileset>
        </batchtest>

Google it, it should sort you out 谷歌,它应该排序你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM