简体   繁体   中英

Laravel code coverage very slow

I'm working on a laravel project that has just over 8000 lines of code and 550 unit tests with coverage around 75%. It is taking 35 minutes to run the code coverage report, this is making integrating with a Continuous Integration environment not possible. Is it normal for phpunit to take this long to generate a coverage report for a project this size? Does anyone know of any way to increase the speed of running the coverage report? I have looked at this other question and this article , neither have proved useful. Increasing the maximum memory limit for a php script has also has no effect.

My environment is: OSX 10.9.5, xDebug 2.2.7, PHP 5.6.5, PHPUnit 4.1.6

You can filter the files that will be included in the coverage report with some configuration in phpunit.xml . For example you don't need to cover the framework or other third party dependencies.

You can do it either including (whitelisting) the files you want to get covered or excluding (blacklisting) the files you don't want.

Start including only some files to see if it makes a difference.

Copied from the PHPUnit docs :

<filter>      
  <whitelist processUncoveredFilesFromWhitelist="true">
    <directory suffix=".php">/path/to/files</directory>
     <file>/path/to/file</file>
    <exclude>
      <directory suffix=".php">/path/to/files</directory>
      <file>/path/to/file</file>
    </exclude>
  </whitelist>
</filter>

When PHPUnit seems to be taking a very long time, I've usually found the problem to be that it is trying to perform coverage over far too much code. If it ever did finish, you'll probably find you were also getting numbers on all the libraries in the vendor directory.

In the phpunit.xml file, I tend to use a complete filter, to make sure pretty much only my primary source code (in the classes) are being run, and have code coverage gathered on them. Here's mine for a Symfony2 based project, with embedded resources.

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
<filter>
    <blacklist>
        <directory>./vendor/</directory>
        <!-- and other directories,  -->
    </blacklist>

    <whitelist>
        <directory>./app</directory>
        <directory>./src</directory>
        <exclude>
            <directory>./app/cache/</directory>
            <directory>./src/*/*Bundle/Resources</directory>
            <directory>./src/*/*Bundle/Tests</directory>
            <directory>./vendor/</directory>
        </exclude>
    </whitelist>
</filter>

In part, with this setup, against 125 src/ files and 8,800 non-comment lines of code, it takes me about 40 seconds to run my subset of 160 tests - 440 assertions, and produce HTML output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM