【问题标题】:Run all unit tests with Ant builder使用 Ant builder 运行所有单元测试
【发布时间】:2011-06-13 05:42:54
【问题描述】:

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

   <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 构建器目标运行项目中的所有单元测试。
可以吗?

【问题讨论】:

    标签: java eclipse ant junit build-process


    【解决方案1】:

    是的,你需要查看文件集标签,例如:

    <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 任务的完整文档以及此处的示例:

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

    【讨论】:

      【解决方案2】:

      是的!我们使用 ant 命令批处理测试来完成它。看起来像这样:

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

      谷歌一下,应该能帮你解决

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-06-24
        • 1970-01-01
        • 2013-07-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-08
        相关资源
        最近更新 更多