【问题标题】:PHPUnit Code coverage not generating reports correctlyPHPUnit 代码覆盖率未正确生成报告
【发布时间】:2014-03-21 08:18:29
【问题描述】:

我的 phpunit xml:

<phpunit bootstrap="bootstrap.php">
    <testsuites>
        <testsuite name="Phase Unit Tests">
            <directory>./Phase</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">Api/app/library</directory>
        </whitelist>
    </filter>
    <logging>
        <log type="coverage-html" target="build/report" charset="UTF-8"
            highlight="false" lowUpperBound="35" highLowerBound="70"/>
            <log type="testdox-html" target="build/testdox.html"/>
        </logging>
    </phpunit>

我的测试运行成功,我没有收到错误。我检查了任何 DIE()EXIT 调用,但在我的代码中没有找到任何调用。当我查看我的报告时,它只是没有扫描文件的空文件夹。

我在带有 Wamp 服务器 2.2 的 Windows 8 上使用 PHP_CodeCoverage 1.2.7,使用 PHP 5.4.3 和 PHPUnit 3.7.13

好的,所以我写了一个小东西来测试 PHPUnit 覆盖率报告......下面是我的课程:

/**
*   test
*/
class Application
{
    public $testprop;

    function __construct()
    {
        $this->testprop = "Stuff";
    }
}

/**
*  Tests for the application class
*/
class ApplicationTest extends PHPUnit_Framework_TestCase
{



    public function testRunTheThing()
    {
        $app = new Application();
        $this->assertEquals($app->testprop, 'Stuff');
    }
}

我在命令提示符下运行以下命令:

phpunit --coverage-html report ApplicationTest.php

测试通过,但生成的代码覆盖率报告是 composer ClassLoader 文件。

【问题讨论】:

  • 这听起来很愚蠢,但我之前已经被我咬过......你真的有测试调用应该被覆盖的代码吗?在实际测试调用代码之前,该目录将显示为空。
  • 我只是仔细检查了一遍。测试实例化对象并测试它是否为对象,因此肯定会被调用。
  • 嗯,也许只是因为构造函数。尝试添加一个方法,例如返回您的属性值...
  • 您好,好像是我使用的版本有bug,更新了phpunit和依赖后,现在好像可以工作了。

标签: php phpunit code-coverage


【解决方案1】:

这似乎是 phpunit 的版本及其依赖项的问题。我在 phpunit 上运行了更新,现在它正在成功生成覆盖率报告。我现在使用 PHP_CodeCoverage 1.2.16、PHP 5.4.3 和 PHPUnit 3.7.32。

【讨论】:

    猜你喜欢
    • 2011-03-09
    • 1970-01-01
    • 1970-01-01
    • 2014-04-16
    • 2017-01-28
    • 2012-08-23
    • 2021-06-26
    • 2019-04-24
    • 2018-05-29
    相关资源
    最近更新 更多