Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Ant builder运行所有单元测试_Java_Eclipse_Ant_Junit_Build Process - Fatal编程技术网

Java 使用Ant builder运行所有单元测试

Java 使用Ant builder运行所有单元测试,java,eclipse,ant,junit,build-process,Java,Eclipse,Ant,Junit,Build Process,在我的项目中,我有一个包含大量JUnit测试的目录。到目前为止,我已经为每个单元测试使用了单独的目标。例如: <target name="MyTest"> <mkdir dir="${junit.output.dir}"/> <junit fork="yes" printsummary="withOutAndErr"> <formatter type="xml"/>

在我的项目中,我有一个包含大量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 builder目标运行项目中的所有单元测试
可以吗?

是的,您需要查看文件集标记,例如:

<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任务的完整文档及示例如下:


是的!我们使用ant命令batchtest来实现这一点。看起来像这样:

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

谷歌搜索一下,它会帮你解决问题的