无法让 hudson 解析 JUnit 测试输出 XML
编辑:谷歌已在 gtest 1.4.0 中修复了此问题; 查看原始错误报告了解详情。
我最近改用 gtest 作为我的 C++ 测试框架,我目前无法使用的它的一项重要功能是能够生成 JUnit 样式的 XML 测试报告,然后我们的 hudson 构建服务器可以读取该报告。
gtest 测试套件生成的 XML 输出看起来都是合法的:
<?xml version="1.0" encoding="UTF-8"?>
<testsuite tests="370" failures="0" disabled="0" errors="0" time="45.61" name="AllTests">
<testsuite name="application" tests="7" failures="0" disabled="0" errors="0" time="8.953">
<testcase name="zero_tasks_on_bootup" status="run" time="0" classname="application" />
...etc.
</testsuite>
</testsuite>
我还尝试将 JUnitReport 任务添加到我的 ant 构建脚本中,它运行良好,并生成如下 XML:
<?xml version="1.0" encoding="UTF-8"?>
<testsuite tests="370" failures="0" disabled="0" errors="0" time="45.61" name="AllTests">
<testsuite name="application" tests="7" failures="0" disabled="0" errors="0" time="8.953">
<testcase name="zero_tasks_on_bootup" status="run" time="0" classname="application" />
...etc.
</testsuite>
</testsuite>
问题是,每当我告诉 ant 发布 JUnit 时测试结果,然后将其指向原始测试结果 XML,或 ant JUnitReport 任务中生成的编译结果,hudson 总是抱怨在那里找不到测试结果。
我不是 java 人员,所以我无法判断这里发生了什么,也找不到 JUnit XML 应该是什么样子的示例。 有人可以帮我指出正确的方向吗?
EDIT: This issue has been fixed by google in gtest 1.4.0; see the original bug report for more information.
I've recently switched to gtest for my C++ testing framework, and one great feature of it which I am presently unable to use is the ability to generate JUnit-style XML test reports, which could then be read in by our hudson build server.
The XML output generated by the gtest test suite all looks legit:
<?xml version="1.0" encoding="UTF-8"?>
<testsuite tests="370" failures="0" disabled="0" errors="0" time="45.61" name="AllTests">
<testsuite name="application" tests="7" failures="0" disabled="0" errors="0" time="8.953">
<testcase name="zero_tasks_on_bootup" status="run" time="0" classname="application" />
...etc.
</testsuite>
</testsuite>
I've also tried adding a JUnitReport task to my ant build script, which works fine, and generates XML like so:
<?xml version="1.0" encoding="UTF-8"?>
<testsuite tests="370" failures="0" disabled="0" errors="0" time="45.61" name="AllTests">
<testsuite name="application" tests="7" failures="0" disabled="0" errors="0" time="8.953">
<testcase name="zero_tasks_on_bootup" status="run" time="0" classname="application" />
...etc.
</testsuite>
</testsuite>
The problem is, whenever I tell ant to publish the JUnit test results, and then point it to either the raw test result XML, or the compiled result generated in the ant JUnitReport task, hudson always complains about finding no test results there.
I'm not a java guy, so I can't tell what's going on here, and I can't find an example of how the JUnit XML ought to look like. Can someone help to point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我是这样做的:
Here's how I do it:
编辑:Google 测试已修复此问题,该问题已包含在 gtest 1.4.0 版本中。 请参阅原始错误报告了解详情。
呸! 我终于找到了这个问题的原因——这是因为 gtest 为所有测试结果生成一个巨大的 XML 文件,而 hudson 期望每个类都有一个 XML 测试报告。 我编写了perl 脚本作为此问题的解决方法。 要使用它,您可以在 ant xml 脚本中创建一个目标,如下所示:
出于某种原因,gtest 也不喜欢从 ant 传递给它的错误样式的斜杠,所以我只为 Windows 创建了 exec ,因为我的 hudson 正在 Windows 服务器上运行。 显然,对于 UNIX,更改为“/”。
我还在 gtest 页面上提出了此问题,还有 Hudson 的问题跟踪器 上的一个,希望如此两个团队中的一个会解决这个问题,因为我没有足够的时间自己动手打补丁……不过,如果这个问题在不久的将来没有得到解决,我可能不得不这样做。 ;)
Edit: Google test has fixed this issue, which is included in the gtest 1.4.0 release. See the original bug report for more info.
Bah! I've finally found the cause of this problem -- it's because gtest produces one giant XML file for all test results, and hudson expects one XML test report per class. I've written a perl script as a workaround for this issue. To use it, you would make a target in your ant xml script which looks something like this:
For some reason, gtest also doesn't like the wrong style of slashes being passed to it from ant, so I made my exec for windows only, as my hudson is running on a windows server. Change to '/' for unix, obviously.
I've also filed an issue for this on the gtest page, and also one on hudson's issue tracker, so hopefully one of the two teams will pick up on the issue, as I don't have enough time to jump in and make a patch myself.... though if this doesn't get fixed in the near future, I might just have to. ;)
我几乎可以肯定,这不是解析 XML 的问题,而是查找 XML 文件的问题。 如果您在 Hudson 配置中使用相对路径,请确保您清楚它相对于哪个目录(我似乎记得在某些情况下它是不明显的)。
至于 JUnit XML 文件应该是什么样子的示例,祝你好运。 任何地方都没有明确指定。 不同的工具有不同的方言。 也就是说,哈德森在认识他们所有人方面做得很好。 我相信 JUnitReport 的开发人员首先引入了 XML 格式,因此,如果您使用这种格式,那么您将获得最规范的格式。
I'm almost certain that this is not a problem parsing the XML but rather a problem finding the XML files. If you are using a relative path in the Hudson config, make sure you are clear which directory it is relative to (I seem to remember it being non-obvious under certain circumstances).
As for examples of what the JUnit XML files are supposed to look like, good luck with that. It's not precisely specified anywhere. Different tools have differing dialects. That said, Hudson does a good job of recognising all of them. I believe it was the developers of JUnitReport who first introduced the XML format, so if you're using that, that's about as canonical as you are going to get.