0
我正在错误Laravel 5:致命错误:类 '的TestCase' 未找到
Fatal error: Class 'TestCase' not found in /home/vagrant/Code/myapp/tests/ExampleTest.php on line 7
运行命令./vendor/bin/phpunit一段时间。我阅读了这个错误,并改变了我的composer.json并添加了TestCase.php文件。但我仍然收到这个错误。
我的文件:
composer.json
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
],
"psr-4": {
"Tests\\": "tests/"
}
}
TestCase.php
<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
}
ExampleTest.php
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testExample()
{
$this->assertTrue(true);
}
}
您正在运行哪个版本的Laravel 5?你可以用'php artisan --version'来检查你正在使用的版本。在5.4.30中,示例单元测试还有一个'use Tests \ TestCase;'语句,命名空间为'namespace Tests \ Unit;' –
@Chris Forrence我正在使用5.3.31版本 – asapa
您有TestCase.php文件匹配Laravel 5.4的格式(具有命名空间和特征使用);如果ExampleTest.php和TestCase.php位于同一个文件夹中,将'namespace Tests'添加到ExampleTest.php文件的顶部 –