Test Your Database Without Mocks
Database mocks are brittle, expensive to maintain, and test little beyond the mock itself, since they skip real behaviour like transactions, isolation levels, foreign keys and referential integrity. The usual reasons to mock, isolation and speed, are better served by copy-on-write database branches than by test containers, which bring resource overhead, port conflicts, cleanup and CI orchestration problems. Neon branches give each developer, test suite or pull request an isolated Postgres copy with real data, created via neonctl or a GitHub Action, optionally from a point in time for debugging. Shared storage and scale-to-zero compute keep the cost low.
Related posts
- Beyond Docker Compose: An Alternative for Deploying Postgres for Testing
Neon mediumAdept
Docker Compose with the official Postgres image gives each developer and CI run an isolated test database, but it struggles with production-like seed data, leftover state between runs, and RAM/CPU overhead. The usual workarounds each cost something: custom data images get bloated, seeding containers slow test startup, shared staging databases cause contention, and tmpfs uses a lot of RAM. Neon's alternative is copy-on-write database branches, which share storage with a parent database and get their own compute, so tests start against prepopulated data in a clean, isolated state. Local containers remain the better fit for offline work, full local control and light testing needs, while branches suit parallel CI and complex test scenarios.
- Stop Mocking Auth (It’s Breaking Your Tests)
Neon mediumAdept
Mocking authentication in tests hides real failures: password hashing and verification, UNIQUE-constraint enforcement under concurrent signups, session handling, and SQL joins between auth and application data. Neon Auth stores users, sessions and tokens in a neon_auth Postgres schema, so a copy-on-write database branch (created in about a second) also branches auth with its own isolated Auth URL. A GitHub Actions workflow can create a branch per pull request, run tests against real auth and data, then delete the branch, giving isolation without mocks or shared staging databases.
- Neon Testing: a Vitest Library for Your Integration Tests
Neon mediumAdept
Neon Testing is an open-source Vitest utility that automates creating and tearing down Neon Postgres branches so each test file runs integration tests against its own isolated, schema-accurate database. Files run in parallel on separate branches. Tests within a file share one branch, and a beforeEach reset gives per-test isolation. A Vite plugin clears DATABASE_URL so tests can't accidentally hit local or production databases, and an autoCloseWebSockets option handles Neon's WebSocket driver. A worked example tests a unique email constraint, the kind of behavior mocks can't reproduce.
- Adopting Neon branching in CI/CD pipelines: a practical story by Shepherd
Neon mediumAdept
Shepherd, an insurtech startup that moved its Alchemist pricing engine from SQLite to Postgres, uses Neon's copy-on-write database branches to give every pull request an ephemeral test database. GitHub Actions call the Neon API to create a branch when a PR opens and delete it on merge. Changes then flow from per-developer and per-PR branches to staging and production, with Render pre-deploy commands applying migrations tracked in a dedicated timestamped table. The team credits branching with removing the cost and effort of keeping test instances synced with production, and notes that scale-to-zero means it no longer pays for idle databases.
- Branching Postgres databases with the Neon API
Neon mediumAdept
Neon branches are copy-on-write clones of a Postgres database that can be created and deleted through the Neon API, giving CI pipelines an isolated copy of production data for end-to-end tests. Two experimental GitHub Actions, neondatabase/create-branch-action and neondatabase/delete-branch-action, wrap the API. A sample pull-request workflow creates a branch from a parent branch, runs the test steps, then deletes the branch. The actions were beta at the time and still being hardened for production use.