【问题标题】:Laravel unit testing class not found errorLaravel 单元测试类未找到错误
【发布时间】:2018-08-05 17:50:32
【问题描述】:

我正在尝试使用 laravel 进行单元测试,但出现以下错误。我不必测试该功能。在我的编辑器中,我正确地看到了对类的引用,但是 phpunit 找不到它。

 Error: Class 'GoCardlessCheck' not found

我的测试是这样的

  use Illuminate\Foundation\Testing\WithoutMiddleware;
  use Illuminate\Foundation\Testing\DatabaseMigrations;
  use Illuminate\Foundation\Testing\DatabaseTransactions;
  use PHPUnit\Framework\TestCase;



class GoCardlessTest extends TestCase
{
/**
 * A basic test example.
 *
 * @return void
 */
 public function testExample()
 {
    $acc = new GoCardlessCheck();

    $acc->CheckAccount('bob','mould','909090','57-77-90');

 }

}

【问题讨论】:

  • 已经导入类GoCardlessCheck ?
  • 导入了课程?你什么意思?

标签: laravel phpunit


【解决方案1】:

我遇到同样的问题随机出现,这就是解决它的原因。

首先,确保包含use path\to\GoCardlessCheck 语句。如果该路径位于 tests 命名空间中,请确保您有

"autoload-dev": {
    "classmap": [
        "tests/"
    ]
}

在您的 composer.json 文件中。

如果一切正常,请尝试运行composer update

执行此操作后,错误消失了,我的测试再次正常运行。

【讨论】:

    猜你喜欢
    • 2016-03-16
    • 2018-12-27
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    • 1970-01-01
    • 2013-11-09
    • 2017-07-05
    • 1970-01-01
    相关资源
    最近更新 更多