如何在 ant junit 任务中过滤 xml 格式化程序的内容?



我正在将 junit 测试用例与当前使用 ant 构建文件的项目集成。我添加了一些测试用例,它们作为构建过程的一部分完美运行。我需要生成一份详细且相关的 junit 报告以及构建。在<junit>里面,我正在使用<formatter>。我面临以下问题:

  1. 如果我使用<formatter type="plain">,它包含的信息非常有限。
  2. 如果我使用<formatter type="xml>,它会打印太多属性。
  3. 我尝试使用org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter编写自定义格式化程序。为此,我需要在构建文件<classpath>中添加ant-x.x.x.jarant-junit-x.x.x.jar。它给出了"存在两个不同的蚂蚁版本">

问题-1:有没有办法限制或过滤要在报表中打印的XML元素,也许是通过重写XML格式化程序或其他方式?

问题2:如何避免上述"两个不同的蚂蚁版本"的例外情况?

如果问题 1 有一些选项,我更喜欢。


[更新-1] 我在蚂蚁中的JUnit任务:

<target name="unit_testing" depends="binary" description="Unit Testing">
<!-- Compile the java code from ${src} into ${build_main} -->
<javac srcdir="${codebase_test}" destdir="${build_test}"
encoding="cp1252" includeantruntime="false"
bootclasspath="C:/Program Files (x86)/Java/jdk1.5.0_07/jre/lib/rt.jar;C:/Program Files/Java/jdk1.5.0_07/jre/lib/rt.jar;"
source="1.5" target="1.5">
<classpath refid="classpath_main" />
<classpath refid="classpath_test" />
<classpath>
<pathelement location="${binary}/binary_x.x.x.jar" />
</classpath>
</javac>
<junit fork="yes" haltonfailure="yes">
<!-- set useFile="true" if output required in files -->
<formatter type="xml" usefile="true" />
<classpath refid="classpath_main" />
<classpath refid="classpath_test" />
<classpath>
<pathelement path="${build_test}" />
<pathelement location="${binary}/binary_x.x.x.jar" />
</classpath>
<batchtest todir="${results_test}">
<fileset dir="${build_test}">
<include name="**/*Test.class" />
</fileset>
</batchtest>
</junit>
</target>

问题 1

请考虑使用<xslt>任务将<junit>生成的 XML 文件作为输入,并使用 XSLT 生成另一个 XML 文件作为输出。

有关使用 XSLT 生成其他文件的示例,请参阅自定义 JUnit 报告。

问题2

不需要在传递给<junit><classpath>上指定ant-x.x.x.jarant-junit-x.x.x.jar

默认情况下,includeantruntimetrue用于<junit>。这意味着ant-x.x.x.jarant-junit-x.x.x.jar已经位于提供给分叉 JUnit 进程的 CLASSPATH 上。

<classpath>中删除ant-x.x.x.jarant-junit-x.x.x.jar将避免multiple versions of ant detected in path for junit警告。

最新更新