---
title: "Functional tests with Testcontainers"
description: "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."
url: "https://swe.quest/articles/functional-tests-with-testcontainers-8e8bddfb01d0b1bc"
canonical: "https://engineering.zalando.com/posts/2022/04/functional-tests-with-testcontainers.html"
source: "Zalando Engineering"
published: "2022-04-11"
difficulty: "medium"
kind: "How-to"
reading_minutes: 7
tags: ["testing","jvm","containers"]
---

# Functional tests with Testcontainers

A post on [Zalando Engineering](https://swe.quest/sources/zalando.md), published 2022-04-11, 7 min read, How-to. Original: [https://engineering.zalando.com/posts/2022/04/functional-tests-with-testcontainers.html](https://engineering.zalando.com/posts/2022/04/functional-tests-with-testcontainers.html)

## Summary

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.

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)
- [Java & JVM](https://swe.quest/tags/jvm.md) (Languages)
- [Containers](https://swe.quest/tags/containers.md) (Infrastructure)

## Prerequisites

- Java and Spring Boot ([easy posts on Java & JVM](https://swe.quest/tags/jvm.md?difficulty=easy))
- Docker basics ([easy posts on Containers](https://swe.quest/tags/containers.md?difficulty=easy))
- JUnit testing ([easy posts on Testing](https://swe.quest/tags/testing.md?difficulty=easy))

## Keywords

Testcontainers, Spring Boot, Docker, PostgreSQL, JUnit 5, Maven, Ryuk

## Related posts

- [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.
- [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.
- [Shift-Left Testing with Testcontainers: Catching Bugs Early with Local Integration Tests](https://swe.quest/articles/shift-left-testing-with-testcontainers-catching-bugs-early-with-local-f90241b596ffcd90.md): Docker · 2025-03-13 · Medium · 10 min read · Testing, Developer productivity, PostgreSQL, TypeScript
  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.
- [Streamlining Local Development with Dev Containers and Testcontainers Cloud](https://swe.quest/articles/streamlining-local-development-with-dev-containers-and-testcontainers-cloud-050962d8604171c1.md): Docker · 2024-08-27 · Medium · 7 min read · Containers, Testing, Developer tools, Java & JVM
  Testcontainers-based tests and services can run inside a dev container by giving the container Docker access, either through the Docker-in-Docker feature or by swapping in the Testcontainers Cloud feature, which runs an agent that points Docker calls at a remote cloud environment.
- [Model-Based Testing with Testcontainers and Jqwik](https://swe.quest/articles/model-based-testing-with-testcontainers-and-jqwik-e941a47b3c07d6eb.md): Docker · 2024-10-23 · Medium · 6 min read · Testing, Java & JVM, Containers
  Model-based testing can regression-test a REST API by running the current version (Postgres-backed) and a candidate version (MySQL-backed) side by side, sending both identical randomly generated request sequences, and comparing their responses.

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)
