Sol*_*oul 5 php phpunit laravel laravel-5
我正在尝试为我的 Laravel (5.2) API 项目设置单元测试。在使用单元测试之前,我想为它们定义一个自定义命名空间,因此我namespace Test;在默认TestCase.php文件中创建了 。就像这样:
namespace Test;
class TestCase extends Illuminate\Foundation\Testing\TestCase
{
...
}
Run Code Online (Sandbox Code Playgroud)
然后我UnitTests在该tests文件夹下创建了一个文件夹,并将单元测试放入该文件夹中,命名空间如下:
namespace Test\UnitTests;
use Test\TestCase;
class CreateAccountTest extends TestCase
{
...
}
Run Code Online (Sandbox Code Playgroud)
现在,当我想运行单元测试时,出现以下错误:
PHP Fatal error: Class 'Test\Illuminate\Foundation\Testing\TestCase' not found in /var/www/ops/tests/TestCase.php on line 6
所以基本上,Laravel 认为该类Illuminate\Foundation\Testing\TestCase是在 Test 命名空间中找到的,而不是IlluminateLaravel 的命名空间中。
我还在文件中配置了以下自动加载composer.json:
"autoload": {
"classmap": [
"database",
"tests"
],
"psr-4": {
"App\\": "app/",
"Test\\": "tests/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
}
Run Code Online (Sandbox Code Playgroud)
我也尝试运行这两个命令但没有成功:
php artisan config:cache composer dump-autoload正如@xmike 在问题的评论中提到的,我没有在命名空间中添加反斜杠。
所以而不是
class TestCase extends Illuminate\Foundation\Testing\TestCase
Run Code Online (Sandbox Code Playgroud)
它应该是
class TestCase extends \Illuminate\Foundation\Testing\TestCase
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1042 次 |
| 最近记录: |