DEV Community

Diogo Kollross
Diogo Kollross

Posted on

Laravel tests naming rules

There is one important information about Laravel testing that may not be obvious when reading the official documentation: the names of test classes and test methods must follow some simple rules stated below.

  • Test classes must end with the suffix Test
  • Test methods must start with the prefix test

This detail has bitten me more than once in the past. You copy and paste ExampleTest.php to create, say, ExampleTest2.php and the artisan command insists in ignoring your otherwise perfect test class!

The explanation is simple: under the hood, php artisan test and php artisan dusk use PHPUnit to run the tests, so default PHPUnit's rules apply. That's why you can also use test annotations if you really want to avoid prefixing your test methods with test:

 * @test
public function sendsConfirmationEmail()
Enter fullscreen mode Exit fullscreen mode

Top comments (0)