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$/'

You should run ./vendor/bin/phpunit --help to get all options with phpunit. And you can run phpunit with some option below to run specific method or class.

--filter <pattern>          Filter which tests to run.

--testsuite <name,...>      Filter which testsuite to run