Run Tests With PHP Artisan Test
Arie Visser • March 29, 2020
php phpunitHow does it work?
Since the release of Laravel 7.x, you can run you tests by executing
php artisan test
as an alternative to running your tests with the phpunit
command.
This command will run all your tests, until the first test that fails.
Differences
The major differences from running your tests with phpunit
can be seen in the output of your terminal.
When we run the tests in this example project about fluent string operations with phpunit
, you will see this output:
When you run the tests with php artisan test
, you will receive this:
Or, if we let one of the tests fail when running phpnunit
you will see this:
Whereas when you run a test that fails with php artisan test
it returns this output:
To summarize, php artisan test
will:
1). Show the actual names of the tests that are running.
2). Stop at the first test that fails, subsequent tests are marked as pending.
3). Show the assertion that fails and the method of the test wherein it is executed.
Arguments
As stated in the Laravel docs, you can pass all the arguments to the test
command that may be passed to the phpunit
command as well, e.g.:
php artisan test --testsuite="Api"
php artisan test --filter="StringOperationsTest"