Pgtestdb's template cloning approach to testing is fast
- Programming
- Developer Tools
- Open Source
- Infrastructure
The post looks at pgtestdb, a small Postgres utility for test suites that need a fresh database often. Instead of rerunning migrations for every test, it migrates once, keeps that database as a template, and asks Postgres to clone it whenever a test needs a clean start. Brandur benchmarked the approach and found it fast enough to make per-test databases realistic, especially when you care about using a real database instead of mocks.
If your backend tests still rebuild schema or lean heavily on fakes, you probably have an easy speed and reliability win available. Pick a real-database strategy that matches your constraints: template clones for isolation and debugging, transactions for raw speed, or shared-state testing when you want concurrency bugs to surface.
-
brandur.org
- Discuss on HN