Laravel Artisan Generator Command: The make:test Command


John Koster

Published on December 7, 2016

The make:test command can be used to quickly generate test files for your application. The command accepts a name argument that will be used as the name of the newly created file and generated class. Generated tests are stored in the tests/ directory by default.

This command will not overwrite any existing test classes that have the same name. An error stating Test already exists! will be displayed instead.

The following example demonstrates how to use the make:test command to generate a new test for Drinks:

1# Create a new test file for our drinks.
2php artisan make:test DrinksTest

A tests/DrinksTest.php file would be created and contain content similar to the following example:

3use Illuminate\Foundation\Testing\WithoutMiddleware;
4use Illuminate\Foundation\Testing\DatabaseMigrations;
5use Illuminate\Foundation\Testing\DatabaseTransactions;
7class DrinksTest extends TestCase
9 /**
10 * A basic test example.
11 *
12 * @return void
13 */
14 public function testExample()
15 {
16 $this->assertTrue(true);
17 }

The make:test command is also capable of generated test classes within nested directories. Accomplish this by separating directory sections using the \ when supplying the test name. A nested directory will be created (test classes are not namespaced by default).

Explore The Blog