Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude directories from phpunit coverage report

Tags:

phpunit

I tried the following configuration:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit>
    <testsuites>
      <testsuite name="My Test Suite">
         <directory suffix=".php">Test/Case/Model</directory>
        <exclude>Test/Case/Model/Behavior</exclude>
      </testsuite>
    </testsuites>
</phpunit>

but it does not exclude the behaviour from coverage report. How to exclude these directories or files from the coverage report?

like image 471
Sougata Bose Avatar asked Aug 13 '13 06:08

Sougata Bose


People also ask

What is the PHPUnit XML configuration file used to organize tests?

The <testsuite> Element.

What is code coverage PHPUnit?

In computer science, code coverage is a measure used to describe the degree to which the source code of a program is tested by a particular test suite. A program with high code coverage has been more thoroughly tested and has a lower chance of containing software bugs than a program with low code coverage.

What is PHPUnit XML file?

PHPUnit uses XML file for configuration. This configuration file can be added to your version control system so all developers get the same output. These settings will help you make sure your tests work the way you want.


1 Answers

Refer to the exclude element phpunit documentation.

Here is an example phpunit.xml:

<?xml version="1.0" encoding="utf-8"?>
<phpunit>
  <filter>
    <whitelist>
      <directory suffix=".php">../</directory>
      <exclude>
        <file>../ext_emconf.php</file>
        <directory suffix=".php">../tests</directory>
      </exclude>
    </whitelist>
  </filter>
</phpunit>
like image 130
cweiske Avatar answered Oct 05 '22 05:10

cweiske