ant junit任务中如何过滤xml格式化程序的内容?
How to filter the contents of xml formatter in ant junit task?
我正在将 junit 测试用例与我当前使用 ant 构建文件的项目集成。我添加了一些测试用例,它们 运行 完美地作为构建过程的一部分。我需要生成一份详细且相关的 junit 报告以及构建。在 <junit>
中,我正在使用 <formatter>
。我面临以下问题:
- 如果我使用
<formatter type="plain">
,它包含的信息非常有限。
- 如果我使用
<formatter type="xml>
,它会打印太多属性。
- 我尝试使用
org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter
编写自定义格式化程序。为此,我需要在构建文件 <classpath>
中添加 ant-x.x.x.jar
和 ant-junit-x.x.x.jar
。它给出 "two different ant versions are present"
问题一:
有没有什么方法可以限制或过滤要在报告中打印的 XML 元素,可能是通过覆盖 XML 格式化程序或其他方式?
问题2:如何避免上述"two different ant version"异常?
如果问题 1 有一些选项,我会更喜欢。
[UPDATE-1] 我在 Ant 中的 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>
task 将 <junit>
生成的 XML 文件作为输入,并使用 XSLT 生成另一个 XML 文件作为输出。
有关使用 XSLT 生成其他文件的示例,请参阅 Custom JUnit Report?。
问题 2
不需要在传递给 <junit>
的 <classpath>
上指定 ant-x.x.x.jar
或 ant-junit-x.x.x.jar
。
默认情况下,对于 <junit>
,includeantruntime
是 true
。这意味着 ant-x.x.x.jar
和 ant-junit-x.x.x.jar
已经在分配给派生的 JUnit 进程的 CLASSPATH 中。
从 <classpath>
中删除 ant-x.x.x.jar
和 ant-junit-x.x.x.jar
将避免 multiple versions of ant detected in path for junit
警告。
我正在将 junit 测试用例与我当前使用 ant 构建文件的项目集成。我添加了一些测试用例,它们 运行 完美地作为构建过程的一部分。我需要生成一份详细且相关的 junit 报告以及构建。在 <junit>
中,我正在使用 <formatter>
。我面临以下问题:
- 如果我使用
<formatter type="plain">
,它包含的信息非常有限。 - 如果我使用
<formatter type="xml>
,它会打印太多属性。 - 我尝试使用
org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter
编写自定义格式化程序。为此,我需要在构建文件<classpath>
中添加ant-x.x.x.jar
和ant-junit-x.x.x.jar
。它给出 "two different ant versions are present"
问题一: 有没有什么方法可以限制或过滤要在报告中打印的 XML 元素,可能是通过覆盖 XML 格式化程序或其他方式?
问题2:如何避免上述"two different ant version"异常?
如果问题 1 有一些选项,我会更喜欢。
[UPDATE-1] 我在 Ant 中的 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>
task 将 <junit>
生成的 XML 文件作为输入,并使用 XSLT 生成另一个 XML 文件作为输出。
有关使用 XSLT 生成其他文件的示例,请参阅 Custom JUnit Report?。
问题 2
不需要在传递给 <junit>
的 <classpath>
上指定 ant-x.x.x.jar
或 ant-junit-x.x.x.jar
。
默认情况下,对于 <junit>
,includeantruntime
是 true
。这意味着 ant-x.x.x.jar
和 ant-junit-x.x.x.jar
已经在分配给派生的 JUnit 进程的 CLASSPATH 中。
从 <classpath>
中删除 ant-x.x.x.jar
和 ant-junit-x.x.x.jar
将避免 multiple versions of ant detected in path for junit
警告。