Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何强制ant打印junit';彩色报告_Java_Ant_Junit - Fatal编程技术网

Java 如何强制ant打印junit';彩色报告

Java 如何强制ant打印junit';彩色报告,java,ant,junit,Java,Ant,Junit,下面是我的build.xml <target name="tdd" description="Run unittest" depends="jar"> <mkdir dir="${build.test.dir}"/> <javac srcdir="${test.src.dir}" destdir="${build.test.dir}" includeAntRuntime="false"> <clas

下面是我的build.xml

    <target name="tdd" description="Run unittest" depends="jar">
    <mkdir dir="${build.test.dir}"/>
    <javac srcdir="${test.src.dir}" destdir="${build.test.dir}"
        includeAntRuntime="false">
        <classpath refid="lib.junit"/>
        <classpath refid="lib.dataquery"/>
    </javac>
    <jar destfile="${build.jar.dir}/dataqueryTDD.jar">
        <fileset dir="${build.test.dir}">
            <include name="**/*.class"/>
        </fileset>
    </jar>
    <mkdir dir="${build.test.report.dir}"/>

    <junit printsummary="yes">
        <classpath refid="lib.junit"/>
        <classpath refid="lib.dataquery"/>
        <classpath refid="lib.dataquery.tdd"/>
        <formatter type="xml"/>
        <batchtest todir="${build.test.report.dir}">
            <fileset dir="${test.src.dir}" includes="**/*Test.java"/>
        </batchtest>
    </junit>

    <junitreport todir="${build.test.report.dir}" tofile="TEST-Summary.xml">
        <fileset dir="${build.test.report.dir}" includes="*.xml"/>
    </junitreport>
</target>

我可以运行它们并打印没有错误的报告

然而,ant只会告诉我测试是否失败。我需要通过命令
cat
手动签出测试报告。我想知道如何强制蚂蚁将失败的测试报告用彩色打印在标准纸上

谢谢

请尝试以下操作:

<!-- new testwithcat target -->
<target name="testwithcat" depends="tdd, catreport"/>

<target name="tdd" description="Run unittest" depends="jar">
    <mkdir dir="${build.test.dir}"/>
    <javac srcdir="${test.src.dir}" destdir="${build.test.dir}"
        includeAntRuntime="false">
        <classpath refid="lib.junit"/>
        <classpath refid="lib.dataquery"/>
    </javac>
    <jar destfile="${build.jar.dir}/dataqueryTDD.jar">
        <fileset dir="${build.test.dir}">
            <include name="**/*.class"/>
        </fileset>
    </jar>
    <mkdir dir="${build.test.report.dir}"/>

<!-- add errorProperty, failureProperty to junit task -->
<junit printsummary="yes" errorProperty="test.failed" failureProperty="test.failed">
        <classpath refid="lib.junit"/>
        <classpath refid="lib.dataquery"/>
        <classpath refid="lib.dataquery.tdd"/>
        <formatter type="xml"/>
        <batchtest todir="${build.test.report.dir}">
            <fileset dir="${test.src.dir}" includes="**/*Test.java"/>
        </batchtest>
    </junit>

    <junitreport todir="${build.test.report.dir}" tofile="TEST-Summary.xml">
        <fileset dir="${build.test.report.dir}" includes="*.xml"/>
    </junitreport>
</target>

<!-- add cat report target that runs if test.failed has been set in junit task -->  
  <target name="catreport" depends="test" if="test.failed">
    <echo message="Test failed - cat the test report"/>
    <!-- customise the following to cat your report in colour -->
    <exec executable="cat">
      <arg value="${build.test.report.dir}/TEST-Summary.xml"/>
    </exec>
  </target>
输出:

Test failed - cat the test report
[content of ${build.test.report.dir}/TEST-Summary.xml]
您需要定制

<exec executable="cat">
    <arg value="${build.test.report.dir}/TEST-Summary.xml"/>
</exec>

你可以用

<report format="frames" todir="${build.test.report.dir}"/>


在junitreport任务中生成html输出

你可以替换

<exec executable="cat">
    <arg value="${build.test.report.dir}/TEST-Summary.xml"/>
</exec>


例如,执行此操作的代码。

谢谢。如果测试失败,我可以编辑报告。然而,
testsummary.xml
的格式并不是一种人性化的。。。是否有用于解析该XML的命令?或者,是否有可能获得失败的测试,以便我可以在关闭
printsummmary
的情况下运行另一个
junit
,以转储这些错误?太好了。谢谢!这两个建议(网页和纯文本)都非常好。就我个人而言,我选择了一个网页,因为它需要较少的代码:D。再次感谢。答案中添加了评论。
<report format="noframes" todir="${build.test.report.dir}"/> 
<exec executable="cat">
    <arg value="${build.test.report.dir}/TEST-Summary.xml"/>
</exec>