Running Backend PHP Unit Tests
Never run
php artisan test. Always usecomposer test:unitfrombackend/; 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:
php artisan clear
php artisan config:clearRunning a single unit Test
To run a specific unit test file, use the following command:
composer test:unit -- 'insert file path here' --stop-on-failureRunning all unit Tests
To run all backend unit tests, use the following command:
composer test:unit -- --stop-on-failureor for a compacter view
composer test:unit