laravel fatal error for TestCase not found

前端 未结 8 1932
离开以前
离开以前 2021-02-12 13:26
http://localhost/laravel/app/tests/ExampleTest.php

if i run laravel it shows the following error

Fatal error: Class \'TestCase\' not found in D

相关标签:
8条回答
  • 2021-02-12 13:57

    Had the same issue with PHPUnit, he would output always the same message : PHP Fatal error: Class 'Tests\TestCase' not found ... and indeed I think he had troubles to find that class so what you need to do is transform one line :

    From this :

    <?php
    
    namespace Tests\Feature;
    
    use Tests\TestCase;
    use Illuminate\Foundation\Testing\WithFaker;
    use Illuminate\Foundation\Testing\RefreshDatabase;
    
    class AnotherTest extends TestCase {
        public function testExample() {
            // Do something
        }
    }
    

    To this :

    <?php
    
    namespace Tests\Feature;
    
    use PHPUnit\Framework\TestCase;
    use Illuminate\Foundation\Testing\WithFaker;
    use Illuminate\Foundation\Testing\RefreshDatabase;
    
    class AnotherTest extends TestCase {
        public function testExample() {
            // Do something
        }
    }
    

    Notice the first line in use and you should do this if there's any other files in the same case

    0 讨论(0)
  • 2021-02-12 13:59

    The is caused by an outdated phpunit. If you using a globally installed phpunit, here is a link on how to update it https://stackoverflow.com/a/40701333/3792206 . Or you can explicitly use the phpunit that was installed with the project.

    0 讨论(0)
提交回复
热议问题