Skip to content

Running Backend PHP Unit Tests

Why use Unit Tests

Unit Tests are used to test small parts of code in isolation, for example a single method, class or some other piece of important logic. We usually do this by verifying the results for some common cases and edge cases. Other times it is to make sure we do not reintroduce a bug we had before. In contrast to Integration Tests we do not interact with the whole system, therefore Unit Tests usually run in a fraction of the time of Integration Tests.

Setup

Follow the steps in Setup.

Before testing

You have to run these two line to avoid some caching issues:

sh
php artisan clear
php artisan config:clear

Running a single unit Test

To run a specific unit test file, use the following command:

sh
php artisan test 'insert file path here' --stop-on-failure

Running all unit Tests

To run all backend unit tests, use the following command:

sh
php artisan test --testsuite=Unit --stop-on-failure

or for a compacter view

sh
composer test:unit