Skip to content

Running Backend PHP Unit Tests ​

Never run php artisan test. Always use composer test:unit from backend/; the Composer script applies the project’s required test bootstrap and safeguards.

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
composer test:unit -- 'insert file path here' --stop-on-failure

Running all unit Tests ​

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

sh
composer test:unit -- --stop-on-failure

or for a compacter view

sh
composer test:unit