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