我有一个运行大量项目的 CruiseControl 构建服务器。在其中之一上,我最近注意到构建报告中仅存在两个测试套件之一(但另一个测试套件的失败仍然会导致构建失败)。
进一步调查表明,ant 的 xmlformatter 生成的 JUnit XML 输出文件(CruiseControl 解析该文件以生成构建报告)在包含系统的 CDATA 部分内包含偶尔出现的 ASCII 代码 7 (BELL) 字符 - 出于测试用例。 Cruiscontrol 显然无法处理这个问题,并且 xmllint 也认为这些字符在 CDATA 部分中是非法的。
不幸的是,我找不到任何可以写这些字符的东西;它们出现在日志输出的特定行的开头,但并非总是如此(尽管日志记录代码总是打印相同的字符串文字)。
并且无论测试用例向其标准输出写入什么内容,xmlformatter 是否都不应生成有效的 XML?
有人遇到过类似的问题吗?
这是 XML 日志文件的相关部分的样子(因为这是一个公司应用程序,所以是匿名的):
<testcase classname="Testclass" name="testMethod" time="0.0020"></testcase>
<system-out><![CDATA[15.10.09 16:49:41.161 (MainUIClass): Starte UI initialize
...
^G15.10.09 16:49:58.881 (SubUiClass): Starte UI initialize
15.10.09 16:49:58.881 (SubUiClass): UI initialize beendet
^G15.10.09 16:49:59.264 (SubUiClass): Starte UI initialize
15.10.09 16:49:59.264 (SubUiClass): UI initialize beendet
这是生成该日志输出的代码:
SystemProperties.getLogger().logInfo(getClass(), "Starte UI initialize");
...
SystemProperties.getLogger().logInfo(getClass(), "UI initialize beendet");
I have a CruiseControl build server running a large number of projects. On one of them I have recently noticed that only one of the two test suites are present in the build report (but failures in the other one still cause the build to fail).
Further investigation showed that the XML output file of JUnit generated by ant's xmlformatter (which CruiseControl parses to produce build reports) contains occasional instances of the ASCII code 7 (BELL) character, inside a CDATA section containing the system-out of a test case. Cruiscontrol apparently cannot deal with this and xmllint also considers these characts illegal within a CDATA section.
Unfortunately, I can't find anything that would write these characters; they appear at the beginning of a particular line of log output, but not always (though the logging code always prints the same string literal).
And shouldn't the xmlformatter produce valid XML no matter what a test case writes to its standard output?
Has anyone had similar problems?
This is how the relevant sections of the XML logfile looks like (anonymized since this is a corporate app):
<testcase classname="Testclass" name="testMethod" time="0.0020"></testcase>
<system-out><![CDATA[15.10.09 16:49:41.161 (MainUIClass): Starte UI initialize
...
^G15.10.09 16:49:58.881 (SubUiClass): Starte UI initialize
15.10.09 16:49:58.881 (SubUiClass): UI initialize beendet
^G15.10.09 16:49:59.264 (SubUiClass): Starte UI initialize
15.10.09 16:49:59.264 (SubUiClass): UI initialize beendet
This is the code producing that log output:
SystemProperties.getLogger().logInfo(getClass(), "Starte UI initialize");
...
SystemProperties.getLogger().logInfo(getClass(), "UI initialize beendet");
发布评论
评论(1)
我现在发现有问题的字符是测试的标准输出流的一部分,并且是由
sun.awt.HeadlessToolkit
的beep()
方法生成的,即java.awt.headless 系统属性设置为
true
时(构建服务器上的情况),使用 >Toolkit 实现。在我看来,这首先是 ant 的 JUnit 日志 xmlformatter 中的一个错误,(我想说)无论 stdout 流中是什么,它都应该生成有效的 XML 输出。
编辑 我使用的是旧版本的ant;当前版本(1.7.1)没有这个问题。
I have now found out that the problematic characters are part of the tests's stdout stream and are produced by the
beep()
method ofsun.awt.HeadlessToolkit
, i.e. theToolkit
implementation that is used when, as is the case on the build server, thejava.awt.headless
system property set totrue
.It seems clear to me that this is first and foremost a bug in ant's xmlformatter for JUnit logs, which (I'd say) should produce valid XML output no matter what is in the stdout stream.
Edit I was using an old version of ant; the current version (1.7.1) does not have this problem.