Hudson CI和PHPUnit:没有任何测试报告包含任何结果

时间:2011-01-09 16:34:19

标签: xml junit hudson phpunit

我试图使用xUnit插件将我的PHPUnit测试集成到Hudson中。在Hudson中使用Ant成功构建之后,控制台输出显示:

记录测试结果
没有任何测试报告包含任何结果

我使用phpunit --log-junit的junit.xml测试输出如下所示:

<testsuites>
  <testsuite name="Unit Tests" tests="1" assertions="1" failures="0" errors="0" time="0.005112">
  <testsuite name="DbTest" file="src/tests/unit/DbTest.php" tests="1" assertions="1" failures="0" errors="0" time="0.005112">
    <testcase name="testConnection" class="DbTest" file="src/tests/unit/DbTest.php" line="4" assertions="1" time="0.005112"/>
    </testsuite>
  </testsuite>
</testsuites>

感谢任何帮助

编辑: 我刚刚创建了一个包含以下内容的测试junit.xml:

<testsuites>
  <testsuite name="DbTest" file="src/tests/unit/DbTest.php" tests="1" assertions="1" failures="0" errors="0" time="0.005112">
    <testcase name="testConnection" class="DbTest" file="src/tests/unit/DbTest.php" line="4" assertions="1" time="0.005112"/>
    </testsuite>
</testsuites>

有了这个,构建成功了。问题似乎是嵌套的-tags。知道如何阻止PHPUnit创建这些嵌套标签吗?

1 个答案:

答案 0 :(得分:3)

我终于使用xslt解决方法在How might I integrate phpunit with Hudson CI?找到了解决方案。

如果有人遇到同样的问题:在项目根目录下的任何位置创建一个新的.xsl文件:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
    <xsl:element name="testsuites">
        <xsl:for-each select="//testsuite[@file]">
                 <xsl:copy-of select="." />
        </xsl:for-each>
    </xsl:element>
</xsl:template>
</xsl:stylesheet>

然后添加到build.xml(不要忘记包含在构建目标中):

<target name="phpunit_to_xunit">
  <xslt in="build/logs/phpunit.xml" out="build/logs/junit.xml" style="phpunit_to_xunit.xsl"/>
</target>

无论如何,这有点麻烦。因此,我已经为xUnit项目创建了一个改进建议。