【问题标题】:PHPUnit code coverage not working with configurationPHPUnit 代码覆盖率不适用于配置
【发布时间】:2010-08-27 18:07:23
【问题描述】:

我的 PHPUnit 设置和覆盖率报告在没有白名单过滤器的情况下工作正常。但是,一旦我添加了一个,报告似乎只是部分生成,好像 PHPUnit 意外退出一样。我没有收到任何错误或警告。

我的配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./bootstrap.php"
         colors="true">
    <testsuites>
        <testsuite name="...">
            <testsuite name="...">
                <directory>./path/to/suite</directory>
            </testsuite>
            <testsuite name="...">
                <directory>./path/to/suite2</directory>
            </testsuite>
            <testsuite name="...">
                <directory>./path/to/suite3</directory>
            </testsuite>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory suffix=".php">../path/to/files</directory>
        </whitelist>
    </filter>

    <logging>
        <log type="coverage-html" target="log/" charset="UTF-8" yui="true" />
    </logging>
</phpunit>

知道可能出了什么问题吗?

【问题讨论】:

    标签: php unit-testing code-coverage phpunit


    【解决方案1】:

    原来在我被列入白名单的文件中有一些脚本会停止程序代码。

    【讨论】:

    • 是的,PHP 代码中的硬DIE()EXIT; 将停止PHPunit 覆盖率报告。
    【解决方案2】:

    很抱歉挖了一个旧的,但我用谷歌搜索了 phpunit 代码覆盖率不起作用,这个出现了。

    我让代码覆盖率正常运行(认为 xdebug 已用于它)并且有一段时间没问题。

    然后,当我创建一个新测试时,它突然停止工作,运行的代码被标记为未覆盖。

    我用phpunit创建的测试类:phpunit-skelgen --test

    那个创建覆盖注释,例如:@covers MyClass::someMethod

    删除它们为我解决了这个问题,现在再次使用 xdebug 并且突然有 100% 的覆盖率。

    关于覆盖范围的评论;仅调用一个方法一次在报告中涵盖它,但大多数情况下不能被视为涵盖。用空值和无效值调用它会覆盖它。

    【讨论】:

      猜你喜欢
      • 2012-05-04
      • 2016-03-31
      • 2018-05-29
      • 2012-08-04
      • 2015-11-08
      • 2012-01-18
      • 2012-01-14
      • 2011-05-27
      • 2021-01-04
      相关资源
      最近更新 更多