DEV Community

Diogo Kollross
Diogo Kollross

Posted on

4

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more