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.




