How to setup Pest test coverage

A Pest plugin is available that gives information on the test coverage for Laravel projects.

Xdebug is required to enable text coverage which can be done with the Xdebug setup guide.

How to setup

Run Pest with the coverage flag.

./vendor/bin/pest --coverage

When I tried I received the following output.

Unable to get coverage using Xdebug. Did you set Xdebug's coverage mode?

Go to the php.ini file where xdebug is setup.

sudo nano /etc/php/8.3/cli/php.ini

Edit or add the following Xdebug mode line to enable coverage mode with Xdebug.

xdebug.mode=develop,debug,coverage

Save the file and try the coverage command again.

./vendor/bin/pest --coverage

You will see the test results and the files checked with the amount of code in those classes that are covered from the current unit tests.