代码之家  ›  专栏  ›  技术社区  ›  Uri

当在ant中运行的JUnit测试失败时,如何记录完整的堆栈跟踪?

  •  1
  • Uri  · 技术社区  · 15 年前

    当JUnit测试在Eclipse中运行时抛出运行时异常时,您可以看到整个堆栈跟踪。

    我们的构建服务器使用ant并运行JUnit,但是失败时的打印输出只提供异常消息,而不是整个“printStackTrace”。有没有一个方便的方法来获得这个功能?

    2 回复  |  直到 15 年前
        1
  •  2
  •   Community Mohan Dere    8 年前

    我已经把这个答案贴到 this question 在意识到这是你的复制品之前。

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

    我认为有一个嵌套元素可以帮到你

      <formatter
        type="brief"
        usefile="false"
      />
    
        2
  •  1
  •   Martin    9 年前

    /**
      * 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;
    }
    

    BaseTestRunner.setPreference("maxmessage", "-1");
    
    推荐文章