---
title: "Shift-Left Testing with Testcontainers: Catching Bugs Early with Local Integration Tests"
description: "Running integration tests locally against real dependencies via Testcontainers catches bugs that unit tests and mocks miss, before code reaches shared CI or staging environments."
url: "https://swe.quest/articles/shift-left-testing-with-testcontainers-catching-bugs-early-with-local-f90241b596ffcd90"
canonical: "https://www.docker.com/blog/shift-left-testing-with-testcontainers/"
source: "Docker"
published: "2025-03-13"
difficulty: "medium"
kind: "How-to"
reading_minutes: 10
tags: ["testing","developer-productivity","postgres","typescript"]
---

# Shift-Left Testing with Testcontainers: Catching Bugs Early with Local Integration Tests

A post on [Docker](https://swe.quest/sources/docker.md), published 2025-03-13, 10 min read, How-to. Original: [https://www.docker.com/blog/shift-left-testing-with-testcontainers/](https://www.docker.com/blog/shift-left-testing-with-testcontainers/)

## Summary

Running integration tests locally against real dependencies via Testcontainers catches bugs that unit tests and mocks miss, before code reaches shared CI or staging environments. A worked TypeScript example shows a user-registration service that allows duplicate emails differing only in case, then compares four ways to catch it. Unit tests miss it, E2E tests catch it too late, mocks must duplicate the validation logic, and a PostgreSQL container test catches it in seconds. The post also estimates DORA-metric gains for the shift-left workflow, such as under 20 minutes versus roughly 2 hours to find and fix a bug, and pitches Testcontainers Cloud for CI and team-scale use.

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)
- [Developer productivity](https://swe.quest/tags/developer-productivity.md) (Engineering practices)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [TypeScript](https://swe.quest/tags/typescript.md) (Languages)

## Prerequisites

- integration testing basics ([easy posts on Testing](https://swe.quest/tags/testing.md?difficulty=easy))
- Docker containers ([easy posts on Containers](https://swe.quest/tags/containers.md?difficulty=easy))

## Keywords

Testcontainers, Testcontainers Cloud, PostgreSQL, DORA metrics, Docker Desktop, TypeORM

## Related posts

- [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.
- [Functional tests with Testcontainers](https://swe.quest/articles/functional-tests-with-testcontainers-8e8bddfb01d0b1bc.md): Zalando Engineering · 2022-04-11 · Medium · 7 min read · Testing, Java & JVM, Containers
  Black-box functional tests for a Spring service can run against the service packaged as a Docker image, with PostgreSQL and other dependencies started as separate containers via Testcontainers.
- [Leveraging Testcontainers for Complex Integration Testing in Mattermost Plugins](https://swe.quest/articles/leveraging-testcontainers-for-complex-integration-testing-in-mattermost-plugins-3edaea4757026529.md): Docker · 2024-10-08 · Medium · 6 min read · Testing, Containers, Go, JavaScript
  Mattermost replaced brittle mock-based plugin tests with Testcontainers-driven integration tests that spin up a Mattermost server, PostgreSQL on an internal Docker network, and optional API mock containers.
- [GoFiber v3 + Testcontainers: Production-like Local Dev with Air](https://swe.quest/articles/gofiber-v3-testcontainers-production-like-local-dev-with-air-d8c159a9b0421bda.md): Docker · 2025-07-17 · Medium · 15 min read · Go, Testing, Developer productivity, Containers, PostgreSQL
  Fiber v3's new Services API lets a Go web app start and stop backing dependencies as part of its own lifecycle, and a Testcontainers contrib module plugs real Docker containers into it.
- [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.

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)
