Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zaster's avatar

Testing - Single Test Feature

php artisan test --filter UserTest

gives the below output

 PASS  Tests\Feature\AuthUserTest
  ✓ an auth user can visit user profile page

   PASS  Tests\Feature\UserTest
  ✓ a guest can access welcome page
  ✓ a guest can access login page
  ✓ a guest can access register page

I need to run only the UserTest Feature

0 likes
17 replies
Sergiu17's avatar

try this

php artisan test --filter=UserTest
1 like
Sergiu17's avatar
phpunit tests/Feature/UserTest.php

and this?

1 like
zaster's avatar

Outputs

Cannot open file "tests/Feature/UserTest".
zaster's avatar

@sergiu17

vendor/bin/phpunit tests/Feature/UserTest.php

Works but without the log

Edit : Without the test descriptions

This is what i get

PHPUnit 9.5.4 by Sebastian Bergmann and contributors.

...                                                                 3 / 3 (100%)

Time: 00:00.284, Memory: 22.00 MB

OK (3 tests, 11 assertions)
bugsysha's avatar

If you run php artisan test --help or php artisan help test you will see that there is no option to filter. So you either use it as is, or you go with the vendor/bin/phpunit --filter/vendor/bin/phpunit path/to/the/file.php option.

1 like
zaster's avatar
vendor/bin/phpunit tests/Feature/UserTest.php

martinbean's avatar
Level 80

@bugsysha Not exactly. @sergiu17’s suggestion was to use Laravel’s test Artisan command, which wraps PHPUnit but not exactly. I’ve had issues with it in the past trying to pass certain PHPUnit flags.

But yes, phpunit will let you run a single test class by specifying the name of the file as an argument. If you want the names of the test cases being ran to be output, then you can specify the --testdox flag:

phpunit tests/Feature/UserTest.php --testdox
bugsysha's avatar

@martinbean nope, his second reply was as I stated. You've probably missed it.

phpunit tests/Feature/UserTest.php
zaster's avatar

@bugsysha I have selected @martinbean 's answer as the BEST ANSWER because it let me run a single test class + outputs the test cases of that single class(which i was expecting as default)

1 like
bugsysha's avatar

@zaster Martin posted that answer about an hour after I've posted mine so no clarification needed from my side ;)

1 like
zaster's avatar

@martinbean This works with some warnings

PHP Warning:  Declaration of PHPUnit\Util\TestDox\CliTestDoxPrinter::printHeader(): void should be compatible with PHPUnit\TextUI\DefaultResultPrinter::printHeader(PHPUnit\Framework\TestResult $result): void in /usr/share/php/PHPUnit/Util/TestDox/CliTestDoxPrinter.php on line 118
PHPUnit 9.5.4 by Sebastian Bergmann and contributors.

User (Tests\Feature\User)
 ✔ A guest can access welcome page
 ✔ A guest can access login page
 ✔ A guest can access register page
Call to undefined method SebastianBergmann\Timer\Timer::resourceUsage()

martinbean's avatar

@zaster Then you’ve got an issue with a package version you’ve installed or something, then.

Please or to participate in this conversation.