Laravel Artisan Generator Command: The make:test Command

December 7, 2016 —John Koster

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:

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

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).

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.