JUnit 日志中的虚假 ^G (BELL) 字符导致 CruiseControl 呕吐

发布于 2024-08-07 19:03:24 字数 1155 浏览 2 评论 0 原文

我有一个运行大量项目的 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");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦开始←不甜 2024-08-14 19:03:24

我现在发现有问题的字符是测试的标准输出流的一部分,并且是由 sun.awt.HeadlessToolkitbeep() 方法生成的,即 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 of sun.awt.HeadlessToolkit, i.e. the Toolkit implementation that is used when, as is the case on the build server, the java.awt.headless system property set to true.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文