Laravel的documentation建议使用DatabaseMigrations
特征在测试之间迁移和回滚数据库。
use Illuminate\Foundation\Testing\DatabaseMigrations;
class ExampleTest extends TestCase
{
use DatabaseMigrations;
/**
* A basic functional test example.
*
* @return void
*/
public function testBasicExample()
{
$response = $this->get('/');
// ...
}
}
然而,我有一些种子数据,我想在我的测试中使用。如果我运行:
php artisan migrate --seed
然后,它可以用于第一个测试,但它无法通过后续测试。这是因为特征回滚迁移,当它再次运行迁移时,它不会为数据库设定种子。如何在迁移过程中运行数据库种子?
https://stackoverflow.com/questions/42350138
复制相似问题