---
title: "Test Your Database Without Mocks"
description: "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."
url: "https://swe.quest/articles/test-your-database-without-mocks-093131d18e46824a"
canonical: "https://neon.com/blog/test-your-database-without-mocks"
source: "Neon"
published: "2025-01-15"
difficulty: "medium"
kind: "Opinion"
reading_minutes: 7
tags: ["testing","postgres","ci-cd"]
---

# Test Your Database Without Mocks

A post on [Neon](https://swe.quest/sources/neon.md), published 2025-01-15, 7 min read, Opinion. Original: [https://neon.com/blog/test-your-database-without-mocks](https://neon.com/blog/test-your-database-without-mocks)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Testing](https://swe.quest/tags/testing.md) (Engineering practices)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [CI/CD](https://swe.quest/tags/ci-cd.md) (Reliability & operations)

## Prerequisites

- unit testing and mocks ([easy posts on Testing](https://swe.quest/tags/testing.md?difficulty=easy))
- Postgres basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))

## Keywords

Neon, neonctl, copy-on-write branching, test containers, GitHub Actions

## Related posts

- [Beyond Docker Compose: An Alternative for Deploying Postgres for Testing](https://swe.quest/articles/beyond-docker-compose-an-alternative-for-deploying-postgres-for-testing-119ea8d590b0c90d.md): Neon · 2025-02-24 · Medium · 8 min read · PostgreSQL, Testing, Containers, CI/CD
  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.
- [Stop Mocking Auth (It’s Breaking Your Tests)](https://swe.quest/articles/stop-mocking-auth-it-s-breaking-your-tests-f37ca9cbb9aaf394.md): Neon · 2025-12-29 · Medium · 8 min read · Testing, Identity & auth, PostgreSQL, CI/CD
  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 Testing: a Vitest Library for Your Integration Tests](https://swe.quest/articles/neon-testing-a-vitest-library-for-your-integration-tests-fb19e0ca01596389.md): Neon · 2025-09-09 · Medium · 3 min read · Testing, PostgreSQL, TypeScript
  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.
- [Adopting Neon branching in CI/CD pipelines: a practical story by Shepherd](https://swe.quest/articles/adopting-neon-branching-in-ci-cd-pipelines-a-practical-story-by-shepherd-7c4ee09d2fb5431a.md): Neon · 2024-07-11 · Medium · 5 min read · CI/CD, PostgreSQL, Schema migrations, Testing, Serverless
  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.
- [Branching Postgres databases with the Neon API](https://swe.quest/articles/branching-postgres-databases-with-the-neon-api-3faf0de941bc811a.md): Neon · 2022-12-07 · Medium · 3 min read · PostgreSQL, CI/CD, Testing
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
