代码覆盖率报告错误地指示控制器的100%覆盖率

时间:2011-01-26 15:58:53

标签: php unit-testing testing phpunit code-coverage

我正在运行一系列PHPunit测试并且有一个报告100%覆盖率的控制器。 然而,在报道报告中,其84行代码中只有5行被标记为“绿色”

我想知道可能导致这个问题的因素是什么?

可能导致它的一个有趣点是'间接调用'。这个特殊的控制器是许多其他控制器的父节点,并且由于许多其他对象从它继承,所以代码可能会在其他地方被调用......但是它不会变成绿色吗?

目前唯一可以转为绿色的方法是__construct方法。

我不知道这实际上是否足够继续,但如果有人对单元测试如何确定覆盖范围有更多的了解,我很乐意听到它。

编辑以回应“Gaurav的评论:

phpunit命令行为phpunit --configuration admin.xml

和admin.xml读取

 <phpunit bootstrap="./admin/applications/admin/bootstrap.php" colors="true">
     <testsuite name="AdminTestSuite">
        <directory suffix=".php">./admin/applications/admin/</directory>        
        <directory suffix=".php">./admin/applications/shared/</directory>
    </testsuite>
     <filter>
         <whitelist>
            <directory suffix=".php">../admin/applications/admin/controllers</directory>
            <directory suffix=".php">../admin/applications/shared/controllers</directory>           
            <directory suffix=".php">../admin/applications/shared/helpers</directory>
            <directory suffix=".php">../admin/lib/controllers</directory>           
            <directory suffix=".php">../admin/lib/helpers</directory>
            <directory suffix=".php">../admin/lib/models</directory>
            <directory suffix=".php">../admin/lib/utils</directory>         
         </whitelist>
         <blacklist>
                 <file>../dm_admin/applications/shared/controllers/DashboardController.php</file>
            <directory suffix=".php">../admin/lib/crons</directory>
         </blacklist>                
     </filter>
     <logging>
         <log type="coverage-html" target="/projects/ut/admin/" charset="UTF-8"
             yui="true" highlight="true"
             lowUpperBound="50" highLowerBound="80"/>
         <log type="testdox-html" target="/projects/ut/admin/testdox.html" />
     </logging>
 </phpunit>

回应jakenoble:

帮助者正在读取100%的覆盖率 The report reading 100% coverage on the helper

但在我们看到的内部 Some text at the top of one of the methods - 1099 lines in all

它持续1099行,偶尔会有绿色...但没有红色。

1 个答案:

答案 0 :(得分:0)

代码覆盖率报告显示了三个不同的分数:类,方法和函数以及行。

Classes是一个关于实体中测试的类数的报告。因此,如果每个文件都有一个类,并且测试该类的一部分,则会在测试100%的类时显示。

如果一个文件中有两个类,并且你测试了一个类,那么你将有50%的类覆盖率。