如何配置的JUnit Ant任务仅在故障产生输出? [英] How do I configure JUnit Ant task to only produce output on failures?

查看:185
本文介绍了如何配置的JUnit Ant任务仅在故障产生输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我配置在蚂蚁的JUnit这样的单元测试将在每个版本中运行。我想输出的没有的将在Ant控制台输出打印测试时,他们正在运行。我并不需要看到后面的测试中的任何输出。

I am configuring JUnit in Ant so that unit tests will be run on each build. I would like the output of failing tests to be printed in the Ant console output whenever they are run. I don't need to see any output from succeeding tests.

下面是我的的build.xml 文件的相关位:

Here is the relevant bit of my build.xml file:

<junit>
    <classpath>
        <pathelement path="${build}"/>
    </classpath>
    <formatter type="brief" usefile="false"/>
    <batchtest>
        <fileset dir="${src}" includes="my/tree/junit/"/>
    </batchtest>
</junit>

这几乎产生我想要的,失败的测试都是在Ant输出详细,但随后的测试还写了以下的输出:

This produces almost what I want, failing tests are detailed in the Ant output, except that succeeding tests also write the following output:

    [junit] Testsuite: my.tree.junit.ExampleTest
    [junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 0.002 sec

我相信我已经试过 junit任务文档中列出的所有组合,其中包括:

I believe I have tried all the combinations listed in the JUnit task documentation, including:


  • printsummary 属性

  • showoutput 属性

  • 格式与各种元素键入

  • printsummary attribute
  • showoutput attribute
  • formatter element with each kind of type

我的用例运行蚂蚁在命令行。就在我写更多的测试,我不想从成功测试的输出是如此之大,输出测试失败滚出屏幕。我只是想蚂蚁要安静,除非有一个失败的测试,需要我的注意。如何配置的Ant / JUnit来做到这一点?

My use case is running ant from the command line. As I write more tests, I don't want the output from succeeding tests to be so large that output from failing tests scrolls off the screen. I just want ant to be quiet unless there's a failing test that needs my attention. How can I configure Ant/JUnit to do this?

我使用Ant版本1.6.4和JUnit 4.6。

I am using Ant version 1.6.4 and JUnit 4.6.

推荐答案

一种可能是与类名属性定义自己的XML格式(和扩展 org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter ,潜在上做<一个什么href=\"http://api.dpml.net/ant/1.6.5/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.html\"><$c$c>endTest() endTestsuite() 的方法)。结果
这格式化会忽略信息消息,只显示故障信息。

One possibility would be to define your own xml formatter with the 'classname' attribute (and extending org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter, potentially doing nothing on endTest() or endTestsuite() methods).
That formatter would ignore info message and only display failure messages.

请注意:此设置提的只有失败显示的可能性测试:

Note: this settings mention the possibility of only displaying failed tests:

<junit showoutput="true"
       fork="true"
       failureproperty="tests.failed"
       errorproperty="tests.failed">
    <batchtest todir="${test.results.dir}">
        <fileset dir="test">
            <include name="**/*Test.java"/>
        </fileset>
    </batchtest>
    <classpath path="${classes.dir}:${junit.jar}:${test.classes.dir}"/>
    <formatter usefile="false" type="brief"/>
    <!-- <formatter type="xml"/> If missing, only displays failed tests -->
</junit>

你测试了吗?

注: showoutput =真正的&LT;格式化类型=简单usefile =FALSE/&GT ; 可能有点问题,这个最近(2012年2月),如图所示票

Note: the "showoutput="true" and <formatter type="brief" usefile="false"/>" can be a bit problematic, as illustrated by this recent (February 2012) ticket)

另一种计算策略是定义你的蚂蚁Juint的测试运行,支持蚂蚁<一个href=\"http://kickjava.com/src/org/apache/tools/ant/taskdefs/optional/junit/JUnitResultFormatter.java.htm\"><$c$c>JUnitResultFormatter和只显示标准错误消息。

Yet another approch would be to define your ant Juint Test runner, supporting ant JUnitResultFormatter and displaying only stderr messages.

的<一个href=\"http://kickjava.com/src/org/eclipse/test/EclipseTestRunner.java.htm\"><$c$c>EclipseTestRunner从日食是一个很好的例子。

The EclipseTestRunner from eclipse is a good example.

这篇关于如何配置的JUnit Ant任务仅在故障产生输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆