Laravel Code Coverage Reports phpunit.xml Example

Today, I wanted to show you a little bit into Laravel PHPUnit testing and code coverage report generation!

Below is the example phpunit.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
  backupStaticAttributes="false"
  bootstrap="bootstrap/autoload.php"
  colors="true"
  convertErrorsToExceptions="true"
  convertNoticesToExceptions="true"
  convertWarningsToExceptions="true"
  processIsolation="false"
  stopOnFailure="false"
  syntaxCheck="false"
  >
  <testsuites>
    <testsuite name="Application Test Suite">
      <directory>./app/tests</directory>
    </testsuite>
  </testsuites>
</phpunit>

Now let’s add the logging code to get the generated reports for the code coverage!

</testsuites>
<logging>
  <log type="coverage-html" target="public/code-coverage" charset="UTF-8"/>
</logging>

The logging code above will generate the HTML files and pop them into the “public/code-coverage” directory, you can go to it in your browser by going to: YOUR_URL/code-coverage

Load Comments