Interview frequency: …
Short answer
RefreshDatabase runs migrations once and isolates each test in a transaction that is rolled back at the end, while DatabaseTransactions wraps only the test in a transaction and requires an already prepared database.
Explanation
RefreshDatabase is the recommended standard. It checks whether tables have been migrated and runs the initial migration only once in the test database, then starts a Transaction before each test method and immediately rolls it back afterward. This provides a clean, deterministic, fast test environment without rebuilding tables for every test.
Code example
class UserTest extends TestCase {
use RefreshDatabase; // Clean reset for every test
}Common mistakes
- Using the older DatabaseMigrations, which rebuilds and drops every table for each individual test method and makes the suite very slow.