Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Docker 10 min read How-to mediumAdept

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

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.

Related posts

  • Test Your Database Without Mocks

    Neon mediumAdept

    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.

  • Functional tests with Testcontainers

    Zalando Engineering mediumAdept

    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. The setup uses a Maven multi-module layout where the functional-tests module has no dependency on service code. Tests talk to the service only through plain JSON over its public REST API, and a shared abstract base class starts containers once with health-check waits, log consumers, a remote debug port and a shutdown hook as a backstop to Ryuk. The approach gives strong confidence during deep refactoring and also verifies the Docker packaging. Its costs are slow container startup (about 4s for Postgres, up to 20s for Localstack), harder debugging, and the need to isolate test data because containers are shared across tests.

  • Leveraging Testcontainers for Complex Integration Testing in Mattermost Plugins

    Docker mediumAdept

    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. A custom Go module exposes helpers for plugin installation, DB access, the Go API client and admin operations, while Testcontainers for Node.js pairs with Playwright for UI-level tests. The approach is used for the AI Copilot plugin (mocked LLM API) and the MS Teams plugin (mocked Microsoft Graph), giving isolated, repeatable tests where teams choose per-test or shared container lifetimes.

  • GoFiber v3 + Testcontainers: Production-like Local Dev with Air

    Docker mediumAdept

    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. A todo app walkthrough uses Go build tags to keep a production config that reads the database URL from the environment, alongside a dev config that launches PostgreSQL 16 via testcontainers-go and reads the connection string from app state. It also sets startup and shutdown context providers with timeouts, and uses air for hot reload. Disabling Ryuk and reusing containers by name keeps the database alive across reloads for a fast inner loop.

  • 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.

The quest for software engineering knowledge.

Look:
Layout: