Performance: Database testing (RefreshDatabase)
MEDIUM IMPACT
This concept affects test execution speed and database state consistency during automated testing.
use RefreshDatabase;
public function testExample() {
// Database refreshed before this test
$this->post('/api/data', [...]);
$this->assertDatabaseHas('table', [...]);
}public function testExample() {
// No database refresh
// Tests run on shared database state
$this->post('/api/data', [...]);
$this->assertDatabaseHas('table', [...]);
}| Pattern | Database Operations | Test Runtime Impact | Reliability | Verdict |
|---|---|---|---|---|
| No database refresh | No reset, shared state | Fast per test | Flaky, unreliable | [X] Bad |
| RefreshDatabase trait | Full reset per test | Slower per test | Reliable, consistent | [OK] Good |