我正在尝试使用DatabaseTransactions特性来测试我的Laravel系统。问题是只有在TestCase上的所有测试都运行后才回滚事务。是否有可能为TestCase中的每个测试都创建一个新的数据库实例?每次测试后的数据库事务
这个测试案例有时会返回所有绿色,但有时不会。当它在写入时执行测试时,一切顺利,但当顺序颠倒时,第一个失败,因为之前创建了一个Lead。我能做什么?
public function testPotentialLeads()
{
factory(Lead::class)->create(['lead_type' => LeadType::POTENTIAL]);
factory(Lead::class)->create();
factory(Lead::class)->create();
$potential_leads = Lead::potentials()->get();
$this->assertEquals(1, $potential_leads->count());
$this->assertEquals(3, Lead::all()->count());
}
public function testAnotherLeadFunction()
{
$lead = factory(Lead::class)->create();
$this->assertTrue(true);
}
你可以使用'setUp()'方法。 – yivi