致命错误:class' testcase'在Laravel 9中找不到
我将项目从Laravel 8更新为Laravel 9,然后试图制作由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);
}
}
但是,当我运行phpunit时,我总是会收到此错误,
PHP Fatal error: Uncaught Error: Class "Tests\TestCase" not found in path/to/SimpleTest.php:9
该如何解决此问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我创建了Fresh Laravel 9应用程序来调查此案。
显然,我的应用程序中TestCase.php的内容与Fresh应用程序中的内容不同。因此,我将testcase.php文件替换为Fresh App中的文件,现在可以使用。
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.