致命错误:class' testcase'在Laravel 9中找不到

发布于 2025-02-10 01:10:11 字数 622 浏览 1 评论 0原文

我将项目从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒人说梦 2025-02-17 01:10:11

我创建了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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文