PHPUnit生成Cobertura格式的代码覆盖率报告

20

我有一个小的PHP项目,使用PHPUnit进行单元测试和覆盖率。我想要生成cobertura XML格式的覆盖率报告。

是否有任何工具或插件可以帮助我实现这一目标?

非常感谢您的帮助。


你曾经解决过这个问题吗?我想生成一个Cobertura XML格式的覆盖率报告,但是我没有找到任何现有的解决方案。 - Nothing
1
不,我好久没看它了。 - Sharath
这个有更新了吗? - fleuryc
也许这个插件可以帮到你 https://github.com/Soyhuce/phpunit-to-cobertura - Mohammad.Kaab
3个回答

26

phpunit和phpcov中刚刚合并了对Cobertura格式的支持,这在phpunit 9.4中可用。

可以通过调用带有此标志的phpunit来生成报告:

phpunit --coverage-cobertura=my-cobertura-coverage.xml

相关的 PR:https://github.com/sebastianbergmann/php-code-coverage/pull/812 - mvorisek

4

您可以在配置文件phpunit.xml中配置Cobertura支持。

这里是一个示例,在<phpunit/>标签中添加以下代码:

  <coverage cacheDirectory=".phpunit.cache/code-coverage"
            processUncoveredFiles="true">
    <include>
      <directory suffix=".php">src</directory>
    </include>
    <report>
      <cobertura outputFile="cobertura.xml"/>
      <html outputDirectory="phpunit-html"/>
      <text outputFile="php://stdout"/>
    </report>
  </coverage>

请注意该示例中的<cobertura/>标记。

-3
PHPUnit生成的用于代码覆盖信息记录的XML格式,与Clover使用的格式有些相似。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接