Fast Tests
Slow tests erode the habit of running them. Key tricks: use in-memory SQLite, minimise RefreshDatabase usage, parallelise with Pest.
Slow tests erode the habit of running them. Key tricks: use in-memory SQLite, minimise RefreshDatabase usage, parallelise with Pest.
// phpunit.xml — SQLite in-memory for speed
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
// Pest parallel execution
./vendor/bin/pest --parallel
// Use DatabaseTransactions instead of RefreshDatabase for read-only tests
use DatabaseTransactions; // rolls back per test — no migration re-run
// Lazy factories for complex objects
$user = User::factory()->lazy(); // does not insert until ->create()
An in-memory SQLite test suite can be 10x faster than MySQL — use it for unit tests.