Java 使用Ant builder运行所有单元测试
在我的项目中,我有一个包含大量JUnit测试的目录。到目前为止,我已经为每个单元测试使用了单独的目标。例如: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"/>
<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>
谷歌搜索一下,它会帮你解决问题的