2

我刚刚创建了一个新的 zend 框架应用程序来尝试单元测试。

我已按照教程进行操作,并且一切似乎都可以正常进行测试。覆盖率报告的显示有问题。它显示了正确的信息,但报告从我的硬盘驱动器的根目录开始,我需要遍历树到我的项目文件夹以查看有用的信息。

这意味着每次运行测试时,我都需要单击 5 个文件夹深处才能获得实际报告。

如何使报告在我的项目文件夹中开始?这是我的 phpunit 配置文件:

<phpunit bootstrap="./bootstrap.php">
    <testsuite name="Application Test Suite">
        <directory>./application</directory>
    </testsuite>
    <testsuite name="Library Test Suite">
        <directory>./library</directory>
    </testsuite>

    <filter>
        <whitelist>
            <directory>../../library/Zend</directory>
            <exclude>
                <directory suffix=".phtml">../application/</directory>
                <file>../application/Bootstrap.php</file>
                <file>../application/controllers/ErrorController.php</file>
            </exclude>          
        </whitelist>
    </filter>

    <logging>
        <log type="coverage-html" target="./log/report" charset="UTF-8" yui="true" 
             hightlight="true" lowupperbound="50" highlowerbound="80">
            <log type="testdox" target="./log/testdox.html">
            </log>
        </log>
    </logging>
</phpunit>
4

2 回答 2

1

我解决了问题...

我需要在白名单中明确指定我的应用程序文件夹。如果为空,则代码覆盖率报告仅从“c:”开始并尝试查找每个“.php”文件。

在白名单部分添加该行后:

<directory>../application/</directory>

它按预期工作。

Since I don't have any library tests in my test folder, including the Zend library folder probably had no effect and the report must have considered the whitelist empty. And because there is no blacklist, it just started from the root.

于 2012-07-22T18:59:07.440 回答
0

代码覆盖率从报告中包含的所有文件的最常见路径开始。因此,如果您的 Web 根目录位于 /var/www 并且您在 /usr/local/zend/ 中包含库,那么最常见的路径将是根路径。

解决方案是排除库路径,因为通常无论如何您都不想测量外部库的代码覆盖率。

于 2012-07-22T10:06:15.387 回答