H2 in-memory: siêu nhanh, không cần Docker, chạy mọi nơi.
Nhược điểm: dialect khác Postgres/MySQL — SQL chạy OK trên H2 nhưng fail production. Không test được stored procedure, extension, migration script đặc thù. Testcontainers: Docker real database — test fidelity cao, bắt real bug. Chậm hơn (Docker pull + startup). Yêu cầu Docker daemon trong CI (thường có trên GitHub Actions, GitLab CI). Chiến lược hybrid:
- Unit tests + H2 cho development loop nhanh
- Testcontainers trong PR check để catch integration bug
- Không dùng shared test database (flaky, data pollution). Testcontainers tốt hơn cho critical path: payment, order processing. H2 vẫn OK cho simple CRUD tests. Trend 2026: Testcontainers trở thành standard — Spring Boot 3.1+ first-class support giảm friction đáng kể