Integration tests verify that multiple components work correctly together — typically testing a service with its real database, or an HTTP handler with real request parsing. They are slower than unit tests (seconds, not milliseconds) but catch wiring bugs that unit tests cannot. Testcontainers spins up real Docker services (PostgreSQL, Redis) for integration tests, then tears them down after. Aim for a test pyramid: many unit tests, fewer integration tests, fewest E2E tests.
Real Postgres container for integration tests.
In-memory SQLite fake is faster but behaves differently from PostgreSQL (different SQL, no window functions, different constraint handling). Testcontainers uses the real database engine — bugs caught in test instead of production.
Instead of manually cleaning test data, wrap each test in a BEGIN/ROLLBACK transaction. No data is ever committed, so no cleanup needed. Tests are completely isolated regardless of execution order.
Create one database schema per test worker: test_worker_1, test_worker_2. Each schema has its own migrated copy. Vitest worker threads run in parallel with zero conflicts.
Sign in to share your feedback and join the discussion.