Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Customize Default Test Stubs

Premium
2 min read

Generally, when you run php artisan make:test, it adds an example test, which is pretty meaningless. So, let's talk about generating a new test class with our custom code.


For example, let's generate a new test.

php artisan make:test SomeTest

When you open that test file, you see an example test that has been added.

tests/Feature/SomeTest.php:

<?php
 
test('example', function () {
$response = $this->get('/');
 
$response->assertStatus(200);
});

When using PHPUnit, the generated test looks like the one below. Comments were also added for the test.

tests/Feature/SomeTest.php:

<?php
 
namespace Tests\Feature;
 
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
 
class SomeTest extends TestCase
{
/**
* A basic feature test example.
*/
public function test_example(): void
{
$response = $this->get('/');
 
$response->assertStatus(200);
}
}

What if you want to avoid making...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (31 h 16 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

No comments yet…