liveBook · Manning

Testcontainers

As explained in Kafka for Architects

Testcontainers is a library for running disposable containerized dependencies during automated tests.

Testcontainers runs a real Kafka cluster in Docker during an integration test, replacing preprovisioned infrastructure while leaving application logic unchanged. It provides stronger confidence than mocks or embedded brokers because tests exercise real network, protocol, and persistence paths. section 10.3.2

The architectural trade-offs are:

  • Compared with EmbeddedKafkaBroker, Testcontainers supports Kafka features and edge cases beyond the Spring ecosystem. section 10.3.2
  • Docker introduces higher resource usage and longer test execution, but reduces false positives from misconfigured mocks. section 10.3.2

Producer and consumer integration tests

A ProfileService test starts a Dockerized Kafka cluster, invokes the producer, and validates the published message. A Customer360Service test sends a message and verifies consumer side effects or service invocations.

How Kafka for Architects covers it

How deep it goes
Explains runtime startup, producer and consumer validation, and infrastructure trade-offs without detailing implementation code.
Examples
Uses ProfileService producer and Customer360Service consumer tests against a Dockerized Kafka cluster.
What it assumes
Assumes Kafka producer and consumer behavior, then contrasts real clusters with embedded brokers and mocks.
What you can do after
Apply it via Testcontainers and Docker to validate Kafka behavior through real network, protocol, and persistence paths.
How it connects
Connects integration testing with Kafka brokers, Docker, producers, consumers, and test configuration.

Also explained in

Compare how 5 books explain Testcontainers →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka for Architects. The section links point to the parts of the book it draws on.