我正在使用ant 1.8.2。讓我們說一個測試失敗,並帶有stackoverflow錯誤。junitreport:xslt在StackOverflowError失敗時有很多換行符/換行符
import junit.framework.TestCase;
/**a failing test */
public class FailingTest extends TestCase
{
public void testFail() {
testFail();// gives stackoverflow- result xml is now a large document
}
}
運行junitreport將失敗,下面的錯誤
[junitreport]的jar:文件://lib/ant-junit.jar /組織/阿帕奇/工具/螞蟻/任務定義/可選/ junit/xsl/junit-frames.xsl:65:57: 致命錯誤! java.lang.StackOverflowError的原因: java.lang.StackOverflowError的
的原因似乎是在測試結果XML文件大的文本內容。
<testcase classname="chs.FailingTest" name="testFail" time="0.012">
<error type="java.lang.StackOverflowError">java.lang.StackOverflowError
at chs.FailingTest.testFail(FailingTest.java:14)
at chs.FailingTest.testFail(FailingTest.java:14)
at chs.FailingTest.testFail(FailingTest.java:14) ....
我想xslt需要修剪並跳過大的錯誤信息。什麼是可能的修復?
//臨時的解決辦法:跳過從結果HTML這樣大的文本編輯 需要在JUnit中,XSLT文件
<xsl:template name="br-replace">
<xsl:param name="word"/>
<xsl:if test="string-length($word) < 31024 "> //very large size here causes stackoverflow
<xsl:choose>
<xsl:when test="contains($word, '
')">
<xsl:value-of select="substring-before($word, '
')"/>
<br/>
<xsl:call-template name="br-replace">
<xsl:with-param name="word" select="substring-after($word, '
')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$word"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
最終的解決辦法:看下面的答案後,我檢查蟻開發網站。 的SVN具有新的XSLT:http://svn.apache.org/viewvc/ant/core/trunk/src/etc/junit-frames-xalan1.xsl?view=co&content-type=text%2Fplain,其更新所述模板是如下面
<xsl:template name="br-replace">
<xsl:param name="word"/>
<xsl:param name="br"><br/></xsl:param>
<xsl:value-of select='stringutils:replace(string($word),"
",$br)'/>
</xsl:template>
螞蟻JUnit使用XSLT 1.0。可悲的。 – Jayan
這提供了一個線索,以查看svn中的新br替換:http://svn.apache.org/viewvc/ant/core/trunk/src/etc/junit-frames-xalan1.xsl?view=co&content-type=文本%2Fplain - 使用這個作爲答案 – Jayan