Home > front end >  Fatal error: Class 'TestCase' not found in laravel 9
Fatal error: Class 'TestCase' not found in laravel 9

Time:06-24

I updated my project from laravel 8 to laravel 9 then I tried to make a test case generated by artisan.

<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class SimpleTest extends TestCase
{
 /**
  * A basic feature test example.
  *
  * @return void
  */
 public function test_example()
 {
     $response = $this->get('/');

     $response->assertStatus(200);
 }
}

But when I run phpunit I always get this error

PHP Fatal error:  Uncaught Error: Class "Tests\TestCase" not found in path/to/SimpleTest.php:9

How can I fix this?

CodePudding user response:

Check out this

laravel fatal error for TestCase not found

It has many suggestions that might help you.

CodePudding user response:

I created fresh Laravel 9 app to investigate this case. Apparently the content of TestCase.php in my app was different from the one in fresh app. So I replace TestCase.php file with the one from fresh app and it works now.

  • Related