Laravel 8 not running newly created tests, and not picking up deleted tests

I’m just getting started with the Laravel 8 testing suite and have opted to create a feature test for my account creation process. I’ve ran php artisan make:test AccountCreation and have written the first test case as a function, however, when I run php artisan test it’s not picking up my feature tests, why?

Equally, if I try to delete the default example test, I get an error telling me that the test can’t be found? What am I missing?

tests/Feature/AccountCreation.php

<?php

namespace TestsFeature;

use IlluminateFoundationTestingRefreshDatabase;
use IlluminateFoundationTestingWithFaker;
use TestsTestCase;

class AccountCreation extends TestCase
{
    /**
     * A basic feature test example.
     *
     * @return void
     */
    public function test_creates_user_account_successfully()
    {
        $response = $this->post('/api/account/create');
        $response->assertStatus(201);
    }
}

Is there a special command I need to run for Laravel to pick up these tests?

no tests

Answer

Because you should append ‘Test’ to your test class, because PHPUnit will check all classes end with Test, so change:

class AccountCreation extends TestCase { ...

to:

class AccountCreationTest extends TestCase { ...

Don’t forget to change your class file name.

Leave a Reply

Your email address will not be published. Required fields are marked *