Logo

dev-resources.site

for different kinds of informations.

Laravel tests naming rules

Published at
1/7/2021
Categories
laravel
testing
standard
rules
Author
diogoko
Categories
4 categories in total
laravel
open
testing
open
standard
open
rules
open
Author
7 person written this
diogoko
open
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

Featured ones: