如何在ant junit任务中过滤xml formatter的内容?

时间:2017-03-24 04:36:52

标签: junit ant formatter

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

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

1 个答案:

答案 0 :(得分:1)

问题1

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

有关使用XSLT生成其他文件的示例,请参阅Custom JUnit Report?

问题2

不应该在传递给ant-x.x.x.jar的{​​{1}}上指定ant-junit-x.x.x.jar<classpath>

默认情况下,<junit> includeantruntimetrue。这意味着<junit>ant-x.x.x.jar已经存在于分配的JUnit进程的CLASSPATH上。

ant-junit-x.x.x.jar删除ant-x.x.x.jarant-junit-x.x.x.jar将避免<classpath>警告。