Nik*_*man 5 c++ junit hudson googletest
编辑:此问题已由谷歌在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>
Run Code Online (Sandbox Code Playgroud)
我还尝试将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>
Run Code Online (Sandbox Code Playgroud)
问题是,每当我告诉ant发布JUnit测试结果,然后将其指向原始测试结果XML或者在ant JUnitReport任务中生成的编译结果时,hudson总是抱怨在那里找不到测试结果.
我不是一个java人,所以我不知道这里发生了什么,我找不到JUnit XML应该是什么样子的例子.有人可以帮助我指出正确的方向吗?
我是这样做的:
<target name="junit" depends="compile-tests" description="run all unit tests">
<mkdir dir="${reports}"/>
<junit haltonfailure="false">
<jvmarg value="-Xms128m"/>
<jvmarg value="-Xmx128m"/>
<classpath>
<path refid="project.classpath"/>
</classpath>
<formatter type="xml"/>
<batchtest fork="yes" todir="${reports}">
<fileset dir="${test}/classes">
<include name="**/*Test*.class"/>
</fileset>
</batchtest>
</junit>
</target>
<target name="generate-reports" depends="junit" description="create JUnit test HTML reports">
<mkdir dir="${reports}"/>
<junitreport todir="${reports}">
<fileset dir="${reports}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${reports}"/>
</junitreport>
</target>
Run Code Online (Sandbox Code Playgroud)
编辑:Google 测试已修复此问题,该问题包含在 gtest 1.4.0 版本中。 有关详细信息,请参阅原始错误报告。
呸! 我终于找到了这个问题的原因——这是因为 gtest 为所有测试结果生成一个巨大的 XML 文件,而 hudson 期望每个类都有一个 XML 测试报告。我编写了一个 perl 脚本作为解决此问题的方法。要使用它,您需要在 ant xml 脚本中创建一个目标,如下所示:
<target name="runtests">
<exec executable="wherever/${ant.project.name}Test" failonerror="false" dir="tests">
<arg value="--gtest_output=xml:${build.dir}\reports\${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>
Run Code Online (Sandbox Code Playgroud)
由于某种原因,gtest也不喜欢从ant传递给它的错误样式的斜杠,所以我只为Windows制作了exec,因为我的hudson在Windows服务器上运行。显然,对于 UNIX,更改为“/”。
我还在gtest 页面上提交了一个问题,并在Hudson 的问题跟踪器上提交了一个问题,所以希望两个团队中的一个能够解决这个问题,因为我没有足够的时间介入并做出一个问题给自己打补丁……不过,如果在不久的将来这个问题没有得到解决,我可能就不得不这样做了。;)
| 归档时间: |
|
| 查看次数: |
20206 次 |
| 最近记录: |