Skip to main content

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? (30 h 33 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…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.