php – Is there a way to disable code coverage in PHPUnit for a single test?-ThrowExceptions

Exception or error:

Every time I run a single unit test in PHPUnit, a code coverage report is also generated. I have an older computer here at work, and if I could disable the code coverage when I don’t need it, that would put less strain on my CPU.

Is there a way to disable the code coverage on a per-test basis? I couldn’t find any command-line switch that would do it.

How to solve:

How about making a copy of your phpunit.xml, removing the <logging> stanza from it, then doing:

phpunit --configuration new.xml

Answer:

Since this is one of google top results, I think it makes sense to point out that since version 4.8 PHPUnit now supports the --no-coverage option to override you xml configuration.

https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-4.8.md

Answer:

You can annotate a test class or test method with @coversNothing. The test(s) then do not contribute to the code coverage report. However, code coverage data will still be collected (slowing down the execution). I plan to optimize this in the future.

Leave a Reply

Your email address will not be published. Required fields are marked *