PHPUnit代码覆盖率 [英] PHPUnit Code Coverage

查看:73
本文介绍了PHPUnit代码覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用单元测试Zend Framework应用程序来学习绳索.到目前为止,我已经设置PHPUnitZend Framework一起使用,并开始编写一些简单的测试用例.

I am learning the ropes with Unit testing Zend Framework applications. So far I have set up PHPUnit to work with Zend Framework and have started writing some simple Test Cases.

我的问题是我想知道为什么Code Coverage尽管在我的phpunit.xml中的日志记录标记中进行了设置却仍然无法工作.

My issue is that I am wondering why Code Coverage does not work in spite of being set in the logging tag in my phpunit.xml.

我没有收到任何错误,但没有生成承保范围报告.

I don't get any error but no coverage report is generated.

但是当我运行phpunit --coverage <dir>

我的phpunit的日志记录部分如下:

The logging section of my phpunit is as below:

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

        <filter>
            <whitelist>
                <directory suffix=".php">../application/</directory>
                <exclude>
                    <directory suffix=".phtml">../application</directory>
                    <file>../application/Bootstrap.php</file>
                    <file>../application/controllers/ErrorController.php</file>
                </exclude>
            </whitelist>
           <logging>
               <log type="coverage-html" target="./log/report" charset="UTF-8" yui="true"
   highlight="true" lowUpperBound="50" highLowerBound="80" />
               <log type="testdox" target="./log/testdox.html" />    
           </logging>
        </filter>
    </phpunit>

有人遇到过吗?那么可能是什么问题?

Anyone encounter this before? What is then likely problem?

推荐答案

这是我的一个项目的phpunit.xml,可以正常工作.如您所见,日志记录部分位于过滤器部分之外,因此这可能是Mark Ba​​ker评论的问题.我选择这个是因为它是一个小项目,非常简单.

Here is the phpunit.xml for one of my projects, this works fine. As you can see, the logging section is outside the filter section, so that is probably your issue as commented by Mark Baker. I chose this one as it is from a small project and is very simple.

<phpunit bootstrap="./bootstrap.php" colors="false">
    <testsuite name="HSSTests">
        <directory>./</directory>
    </testsuite>

    <filter>
        <whitelist>
            <directory suffix=".php">d:/wamp/app_hss/</directory>
            <exclude>
                <directory suffix=".phtml">d:/wamp/app_hss/</directory>
                <directory suffix=".php">d:/wamp/app_hss/tests/</directory>
            </exclude>
        </whitelist>
    </filter>

    <logging>
        <log type="coverage-html" target="./log/codeCoverage" charset="UTF-8"
            yui="true" highlight="true"
            lowUpperBound="50" highLowerBound="80"/>
        <log type="testdox-html" target="./log/testdox.html" />
    </logging>
</phpunit>

您可能需要的所有信息都在 PHPunit手册中.

All the information you could ever need on this is in the PHPunit manual.

这篇关于PHPUnit代码覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆