当我尝试使用/vendor/bin/phpunit
在laravel中运行所有测试时,出现以下错误:
There was 1 error:
1) Tests\Unit\Services\PropertyServiceTest::testCreateProperty
Illuminate\Database\QueryException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'omega-testing.properties' doesn't exist (SQL: insert into `properties` (`name`, `description`, `address_line1`, `length`, `services`, `bathrooms`, `bedrooms`, `price`, `latitude`, `longitude`, `updated_at`, `created_at`) values (Sonny Rutherford, sit sapiente ipsa adipisci debitis, 62895 Gretchen Gardens Suite 795
Harveyburgh, SD 29937-4999, 3.1600498, amet tempore ut voluptatem ut, doloremque debitis sequi quam nemo, 1, 43199635, , , 2018-11-02 01:37:01, 2018-11-02 01:37:01))
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Connection.php:624
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Connection.php:459
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Connection.php:411
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php:32
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2558
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:1318
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:821
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:786
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:649
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:790
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Support/helpers.php:1023
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:791
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:23
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1608
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1620
/Users/jacobotapia/Documents/Espora/omega-webapp/app/Services/PropertyService.php:29
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:223
/Users/jacobotapia/Documents/Espora/omega-webapp/tests/Unit/Services/PropertyServiceTest.php:34
Caused by
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'omega-testing.properties' doesn't exist
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Connection.php:452
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Connection.php:657
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Connection.php:624
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Connection.php:459
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Connection.php:411
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php:32
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2558
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:1318
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:821
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:786
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:649
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:790
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Support/helpers.php:1023
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:791
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:23
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1608
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1620
/Users/jacobotapia/Documents/Espora/omega-webapp/app/Services/PropertyService.php:29
/Users/jacobotapia/Documents/Espora/omega-webapp/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:223
/Users/jacobotapia/Documents/Espora/omega-webapp/tests/Unit/Services/PropertyServiceTest.php:34
我配置了.env.testing,其内容如下:
APP_ENV=testing
APP_KEY=base64:6AiBWxoh8mYOTXbDPyVfEQgM4i3A7YoQC0o0x/0m62I=
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=omega-testing
DB_USERNAME=goal
DB_PASSWORD=goal
BCRYPT_ROUNDS=4
CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=array
MAIL_DRIVER=array
我不知道为什么在运行测试之前phpunit不迁移。我试图进行迁移,在迁移命令中添加--env = testing
,然后运行测试,但是phpunit首先删除所有表,然后不再进行迁移。
我不知道发生了什么事。
答案 0 :(得分:0)
为什么不尝试以下操作:
php artisan config:clear
现在,运行后:
php artisan migrate
其后:
vendor / bin / phpunit
答案 1 :(得分:0)
问题出在我的测试文件的导入上。
首先,我要导入use Tests\TestCase;
并将其扩展。
当我更改为use Tests\TestDatabaseCase;
并扩展TestDatabaseCase时,一切正常。