Laravel 代码覆盖率

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20682289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:46:39  来源:igfitidea点击:

Laravel Code Coverage

phplaravelphpunit

提问by user2108258

I'm trying to get my code coverage report to cover all of my laravel application code ( Controllers and Models ). For some reason it is only covering one test. Is there something wrong with this configuration below?

我试图让我的代码覆盖率报告涵盖我所有的 Laravel 应用程序代码(控制器和模型)。出于某种原因,它只涵盖了一项测试。下面这个配置有问题吗?

<phpunit colors="true"
         bootstrap="/Users/bob/projects/leonardo2/laravel/cli/tasks/test/phpunit.php"
         backupGlobals="false">

  <testsuites>
    <testsuite name="Test Suite">
                        <directory suffix=".test.php">/Users/bob/projects/leonardo2/application/tests</directory>
                  </testsuite>
  </testsuites>

  <filter>
    <blacklist>       
        <exclude>
          <directory suffix=".test.php">/Users/bob/projects/leonardo2/application/tests</directory>
        </exclude>
    </blacklist>
    <whitelist>
      <exclude>
        <directory suffix=".php">/Users/bob/projects/leonardo2/application/config</directory>       
        <directory suffix=".php">/Users/bob/projects/leonardo2/application/views</directory>
        <directory suffix=".php">/Users/bob/projects/leonardo2/application/migrations</directory>
        <directory suffix=".php">/Users/bob/projects/leonardo2/application/libraries</directory>
        <directory suffix=".php">/Users/bob/projects/leonardo2/application/tasks</directory>
        <directory suffix=".php">/Users/bob/projects/leonardo2/application/language</directory>
      </exclude>
    </whitelist>
  </filter>

   <logging>
      <log type="coverage-html" target="./storage/work/report/" charset="UTF-8"
       highlight="false" lowUpperBound="35" highLowerBound="70"/>
    </logging>
</phpunit>

回答by jishan

So much complex conditioning is not needed I guess. Just add the app directory in the whitelist under filter tag.

我猜不需要这么多复杂的调节。只需在过滤器标签下的白名单中添加应用程序目录。

<filter>
    <whitelist>
        <directory suffix=".php">app/</directory>
    </whitelist>
</filter>

follow this link for a better understanding. Add Code Coverage Report to Laravel Project

请点击此链接以获得更好的理解。 向 Laravel 项目添加代码覆盖率报告