开发者

How to get full stack traces logged when a JUnit test running in ant fails?

When a JUnit test throw开发者_运维知识库s a runtime exception while running in Eclipse, you can see the entire stack trace.

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.

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"
  />


There is a setting in JUnit BaseTestRunner limiting this value:

/**
  * Truncates a String to the maximum length.
  */
public static String truncate(String s) {
    if (fgMaxMessageLength != -1 && s.length() > fgMaxMessageLength)
        s= s.substring(0, fgMaxMessageLength)+"...";
    return s;
}

You can change this value by setting:

BaseTestRunner.setPreference("maxmessage", "-1");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜