我正在将junit测试用例与我当前使用ant构建文件的项目集成。我添加了一些测试用例,它们在构建过程中完美运行。我需要生成一个详细的,相关的junit报告以及build。在<junit>
内,我正在使用<formatter>
。我正面临以下问题:
<formatter type="plain">
,则其中包含非常有限的信息。<formatter type="xml>
,则会打印太多属性。org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter
编写自定义格式化程序。为此,我需要在构建文件ant-x.x.x.jar
中添加ant-junit-x.x.x.jar
和<classpath>
。它给出了“两种不同的蚂蚁版本存在”问题-1: 有没有什么办法可以限制或过滤要在报告中打印的XML元素,可能是通过重写XML格式化程序或其他方式?
问题2:如何避免“两种不同的蚂蚁版”的上述异常?
如果对问题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>
答案 0 :(得分:1)
考虑使用<xslt>
task将<junit>
生成的XML文件作为输入,并使用XSLT生成另一个XML文件作为输出。
有关使用XSLT生成其他文件的示例,请参阅Custom JUnit Report?。
不应该在传递给ant-x.x.x.jar
的{{1}}上指定ant-junit-x.x.x.jar
或<classpath>
。
默认情况下,<junit>
includeantruntime
为true
。这意味着<junit>
和ant-x.x.x.jar
已经存在于分配的JUnit进程的CLASSPATH上。
从ant-junit-x.x.x.jar
删除ant-x.x.x.jar
和ant-junit-x.x.x.jar
将避免<classpath>
警告。