當在Eclipse中運行時JUnit測試引發運行時異常時,您可以看到整個堆棧跟蹤。如何在Ant中運行的JUnit測試失敗時記錄完整的堆棧跟蹤?
我們的構建服務器使用ant並運行JUnit,但失敗時的打印輸出僅提供異常消息,而不是整個「printStackTrace」。有沒有一種方便的方法來獲得這個功能?
當在Eclipse中運行時JUnit測試引發運行時異常時,您可以看到整個堆棧跟蹤。如何在Ant中運行的JUnit測試失敗時記錄完整的堆棧跟蹤?
我們的構建服務器使用ant並運行JUnit,但失敗時的打印輸出僅提供異常消息,而不是整個「printStackTrace」。有沒有一種方便的方法來獲得這個功能?
我已經發布了這個答案this question才意識到它是你的副本。
這是我的junit標籤,它產生異常跟蹤。
<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"
/>
有JUnit中BaseTestRunner限制該值的設置:
/**
* 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");