如何将 JUnit Ant 任务配置为仅在失败时生成输出?
我正在 Ant 中配置 JUnit,以便在每个构建上运行单元测试。 我希望无论何时运行失败测试的输出都可以打印在Ant控制台输出中。 我不需要看到后续测试的任何输出。
这是我的 build.xml
文件的相关部分:
<junit>
<classpath>
<pathelement path="${build}"/>
</classpath>
<formatter type="brief" usefile="false"/>
<batchtest>
<fileset dir="${src}" includes="my/tree/junit/"/>
</batchtest>
</junit>
这几乎产生了我想要的结果,失败的测试在 Ant 输出中详细说明,除了成功的测试还会写入以下输出:
[junit] Testsuite: my.tree.junit.ExampleTest [junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 0.002 sec
我相信我已经尝试过JUnit 任务文档中列出的所有组合,包括:
printsummary< /code> 属性
showoutput
属性formatter
元素以及每种type
我的用例是从命令运行 ant
线。 当我编写更多测试时,我不希望成功测试的输出太大,以致失败测试的输出滚出屏幕。 我只是希望 ant 保持安静,除非有一个失败的测试需要我的注意。 我如何配置 Ant/JUnit 来做到这一点?
我正在使用 Ant 版本 1.6.4 和 JUnit 4.6。
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.
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>
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
I believe I have tried all the combinations listed in the JUnit task documentation, including:
printsummary
attributeshowoutput
attributeformatter
element with each kind oftype
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?
I am using Ant version 1.6.4 and JUnit 4.6.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种可能是使用“
classname
”属性定义您自己的 xml 格式化程序(并扩展org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter
,可能在endTest()
或endTestsuite()
方法)。该格式化程序将忽略信息消息并仅显示失败消息。
注意:此设置仅提及可能性显示失败的测试:
你测试过吗?
注意:“
showoutput="true"
和
” 可能有点问题,如这张最近(2012 年 2 月)票)所示方法是定义您的 ant Juint Test 运行程序,支持 ant
JUnitResultFormatter
并仅显示 stderr 消息。Eclipse 中的
EclipseTestRunner
是好例子。One possibility would be to define your own xml formatter with the '
classname
' attribute (and extendingorg.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter
, potentially doing nothing onendTest()
orendTestsuite()
methods).That formatter would ignore info message and only display failure messages.
Note: this settings mention the possibility of only displaying failed tests:
Did you test that ?
Note: the "
showoutput="true"
and<formatter type="brief" usefile="false"/>
" can be a bit problematic, as illustrated by this recent (February 2012) ticket)Yet another approch would be to define your ant Juint Test runner, supporting ant
JUnitResultFormatter
and displaying only stderr messages.The
EclipseTestRunner
from eclipse is a good example.