how to test specific test class using phpunit in laravel

After trying several ways, I found out that I don't need to include the folder to test the specific test class. This works for me it runs all the test on the class:

phpunit --filter ApplicationVersionFormatTest

I think it's because my ApplicationVersionFormatTest extend The TestCase and return application instance which serves as the "glue" for all the components of Laravel.


For newer version this might work

php artisan test --filter {MethodName}

// for instance
php artisan test --filter test_example

OR

php artisan test --filter {ClassName}::{MethodName}

//for instance
php artisan test --filter ExampleTest::test_example

To do the same thing using artisan run:

php artisan test --filter ApplicationVersionFormatTest

for run phpunit test in laravel by many ways ..

vendor/bin/phpunit --filter methodName className pathTofile.php

vendor/bin/phpunit --filter 'namespace\\directoryName\\className::methodName'

for test single class:

vendor/bin/phpunit tests/Feature/UserTest.php
vendor/bin/phpunit --filter  tests/Feature/UserTest.php
vendor/bin/phpunit --filter 'Tests\\Feature\\UserTest'
vendor/bin/phpunit --filter 'UserTest' 

for test single method:

 vendor/bin/phpunit --filter testExample 
 vendor/bin/phpunit --filter 'Tests\\Feature\\UserTest::testExample'
 vendor/bin/phpunit --filter testExample UserTest tests/Feature/UserTest.php

for run tests from all class within namespace:

vendor/bin/phpunit --filter 'Tests\\Feature'

for more way run test see more