6

为什么我需要这个?我正在 symfony 项目上运行测试(并使用 Zend fw),phpunit 为所有受影响的文件生成三叶草。但我不想看到 symfony 和 Zend 库(以及所有其他第三方库)的报道。我希望只看到我的代码的覆盖率。或者可能这应该做三叶草查看器?我正在为 hudson 使用 clover 插件,但它不支持查看特定来源。clover 插件显示,我的代码只覆盖了 20%,这是不正确的,因为它也考虑了 symfony 和 Zend 库。

顺便说一句,可能还有其他方法可以得到这个吗?

4

2 回答 2

10

您需要为 phpunit 创建一个配置文件,在该配置文件中,您可以将特定文件或目录排除在代码覆盖范围之外。

示例文件如下所示:

<phpunit stopOnFailure="false">
    <testsuite name="Name">
    </testsuite>

<filter>
    <whitelist>
            <directory suffix=".php">../php</directory>
            <exclude>
                    <file>../php/somefile.php</file>
                    <directory suffix=".php">../php/pdf</directory>
            </exclude>
    </whitelist>
</filter>

<logging>


        <log type="coverage-html" target="target-dir/coverage" charset="UTF-8" yui="true" highlight="true"/>
        <log type="coverage-clover" target="target-dir/build/logs/clover.xml"/>
</logging>

</phpunit>

对于上面的文件,../php 下的所有内容(这是相对于测试所在目录和执行 phprun 的目录)都包含在代码覆盖范围内,除了文件 ../php/somefile.php 和所有扩展名为 .目录中的 ../php/pdf 中的 php

将此文件命名为 phpunit.xml,将其放入运行测试的同一目录中。他们,如果你运行 phpunit,它会选择 conf。

如果你不能使用这个特定的文件名,你可以从命令行给出名称

phpunit --configuration yourconf.xml

有关 phpunit 配置文件的更多详细信息,请访问:http ://phpunit.de/manual/3.7/en/appendixes.configuration.html

于 2010-09-07T17:14:00.537 回答
0

我认为配置xml文件的过滤注释必须被loggin节点包裹:

像这样:

<phpunit stopOnFailure="false">
    <testsuite name="Name"></testsuite>

    <logging>
        <filter>
                <whitelist>
                        <directory suffix=".php">../php</directory>
                        <exclude>
                                <file>../php/somefile.php</file>
                                <directory suffix=".php">../php/pdf</directory>
                        </exclude>
                </whitelist>
        </filter>

        <log type="coverage-html" target="target-dir/coverage" charset="UTF-8" yui="true" highlight="true"/>
        <log type="coverage-clover" target="target-dir/build/logs/clover.xml"/>
    </logging>

于 2012-10-05T10:29:58.723 回答