无法让 hudson 解析 JUnit 测试输出 XML
EDIT:此问题已在 gtest 1.4.0 中由 google 修复;查看原始错误报告了解更多信息.
EDIT: This issue has been fixed by google in gtest 1.4.0; see the original bug report for more information.
我最近为我的 C++ 测试框架切换到 gtest,我目前无法使用它的一个重要功能是能够生成 JUnit 样式的 XML 测试报告,然后我们的 hudson 可以读取这些报告构建服务器.
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.
gtest 测试套件生成的 XML 输出看起来都是合法的:
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>
我还尝试将 JUnitReport 任务添加到我的 ant 构建脚本中,该任务运行良好,并像这样生成 XML:
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>
问题是,每当我告诉 ant 发布 JUnit 测试结果,然后将其指向原始测试结果 XML 或 ant JUnitReport 任务中生成的编译结果时,hudson 总是抱怨在那里找不到测试结果.
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.
我不是 Java 专家,所以我不知道这里发生了什么,而且我找不到 JUnit XML 应该是什么样子的示例.有人可以帮我指明正确的方向吗?
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?
推荐答案
Edit:Google 测试已修复此问题,该问题已包含在 gtest 1.4.0 版本中.查看原始错误报告了解更多信息.
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.
呸!我终于找到了这个问题的原因――这是因为 gtest 为所有测试结果生成了一个巨大的 XML 文件,而 hudson 期望每个类有一个 XML 测试报告.我已经编写了一个 perl 脚本来解决这个问题.要使用它,您需要在 ant xml 脚本中创建一个目标,如下所示:
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:
<target name="runtests">
<exec executable="wherever/${ant.project.name}Test" failonerror="false" dir="tests">
<arg value="--gtest_output=xml:${build.dir}eports${ant.project.name}.xml"/>
</exec>
<!-- Workaround for broken gtest output -->
<mkdir dir="${build.dir}/reports/output"/>
<exec executable="perl" failonerror="false" dir="tests">
<arg value="gtest-hudson.pl"/>
<arg value="${build.dir}/reports/${ant.project.name}.xml"/>
<arg value="${build.dir}/reports/output"/>
</exec>
</target>
出于某种原因,gtest 也不喜欢从 ant 传递给它的错误样式的斜杠,所以我只为 windows 制作了 exec,因为我的 hudson 在 windows 服务器上运行.显然,对于 unix 更改为/".
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.
我还在 gtest 页面上为此提交了一个问题,以及 hudson 的问题跟踪器,所以希望两支球队中的一支能够解决这个问题,因为我没有足够的时间自己动手制作补丁......不过如果这在不久的将来没有得到解决,我可能会只是必须.;)
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. ;)
相关文章