---
title: "Stop Mocking Auth (It’s Breaking Your Tests)"
description: "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."
url: "https://swe.quest/articles/stop-mocking-auth-it-s-breaking-your-tests-f37ca9cbb9aaf394"
canonical: "https://neon.com/blog/stop-mocking-auth-its-breaking-your-tests"
source: "Neon"
published: "2025-12-29"
difficulty: "medium"
kind: "How-to"
reading_minutes: 8
tags: ["testing","identity-auth","postgres","ci-cd"]
---

# Stop Mocking Auth (It’s Breaking Your Tests)

A post on [Neon](https://swe.quest/sources/neon.md), published 2025-12-29, 8 min read, How-to. Original: [https://neon.com/blog/stop-mocking-auth-its-breaking-your-tests](https://neon.com/blog/stop-mocking-auth-its-breaking-your-tests)

## Summary

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.

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)
- [Identity & auth](https://swe.quest/tags/identity-auth.md) (Security)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [CI/CD](https://swe.quest/tags/ci-cd.md) (Reliability & operations)

## Prerequisites

- unit testing with mocks ([easy posts on Testing](https://swe.quest/tags/testing.md?difficulty=easy))
- PostgreSQL basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- GitHub Actions ([easy posts on CI/CD](https://swe.quest/tags/ci-cd.md?difficulty=easy))

## Keywords

Neon Auth, Neon, Better Auth, GitHub Actions, copy-on-write branching

## Related posts

- [Handling Auth in a Staging Environment](https://swe.quest/articles/handling-auth-in-a-staging-environment-18efe1e68fa29994.md): Neon · 2026-01-10 · Medium · 7 min read · Identity & auth, PostgreSQL, CI/CD, Testing
  Neon Auth stores users, sessions and OAuth data in a neon\_auth schema inside the Postgres database, so branching the database also branches auth state via copy-on-write.
- [Test Your Database Without Mocks](https://swe.quest/articles/test-your-database-without-mocks-093131d18e46824a.md): Neon · 2025-01-15 · Medium · 7 min read · Testing, PostgreSQL, CI/CD
  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.
- [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.
- [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.

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)
