Run only one unit test from a test suite in laravel
Use this command to run a specific test from your test suite.
phpunit --filter {TestMethodName}
If you want to be more specific about your file then pass the file path as a second argument
phpunit --filter {TestMethodName} {FilePath}
Example:
phpunit --filter testExample path/to/filename.php
Note:
If you have a function named testSave
and another function named testSaveAndDrop
and you pass testSave
to the --filter
like so
phpunit --filter testSave
it will also run testSaveAndDrop
and any other function that starts with testSave*
it is basically a sub-string match. If you want to exclude all other methods then use $
end of string token like so
phpunit --filter '/testSave$/'
For windows environment this works for me:
in console:
vendor\bin\phpunit --filter login_return_200_if_credentials_are_fine tests/Unit/Http/Controllers/AuthControllerTest.php
WHERE
login_return_200_if_credentials_are_fine - your test methodtests/Unit/Http/Controllers/AuthControllerTest.php - path where test method defined