问题描述
当 JUnit 测试在 Eclipse 中运行时抛出运行时异常时,您可以看到整个堆栈跟踪.
When a JUnit test throws a runtime exception while running in Eclipse, you can see the entire stack trace.
我们的构建服务器使用 ant 并运行 JUnit,但失败时的打印输出仅提供异常消息,而不是整个printStackTrace".有没有方便的方法来获得这个功能?
Our build server uses ant and runs JUnit, but the printout on failure only provides the exception's message, not the entire "printStackTrace". Is there a convenient way to get this functionality?
推荐答案
我已将此答案发布到 这个问题 在意识到它是你的重复之前.
I've posted this answer to this question before realizing that it was a duplicate of yours.
这是我的 junit 标记,它确实产生了异常跟踪.
Here is my junit tag that does produce the exception trace.
<junit
showoutput="yes"
errorProperty="test.failed"
failureProperty="test.failed"
haltOnFailure="${test.halt-on-failure}"
fork="yes"
forkmode="${junit.forkmode}"
>
<classpath>
<pathelement location="${classes.dir}"/>
<pathelement location="${classes-under-test.classes.dir}" />
</classpath>
<!-- #Formatters for capture and display -->
<formatter
type="brief"
usefile="false"
/>
<formatter type="brief" />
<formatter
type="xml"
if="test.generate.xml.output"
/>
<!-- #Test case isolation technique -->
<test
name="${testcase}"
if="testcase"
/>
<batchtest
todir="${test.data.dir}"
unless="testcase"
>
<fileset dir="${classes.dir}">
<include name="**/Test*.class" />
<exclude name="**/Test*$*.class" />
</fileset>
</batchtest>
</junit>
我认为最适合您的嵌套元素是
I think the one nested element that will do it for you is
<formatter
type="brief"
usefile="false"
/>
这篇关于当在 ant 中运行的 JUnit 测试失败时,如何记录完整的堆栈跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!