Appearance
Fresh
Run tests
Back
Testing Spring Boot Kafka Listener using Testcontainers
Learn how to create a Spring Boot application with a Kafka listener that persists data in MySQL, then test it using Testcontainers Kafka and MySQL modules with Awaitility.
Java Testing with Docker
25 minutes
Run tests and next steps
Copy as Markdown
Open MarkdownAsk Docs AIClaudeOpen in Claude
Table of contents
Run the tests
console
$ ./mvnw testOr with Gradle:
console
$ ./gradlew testYou should see the Kafka and MySQL Docker containers start and all tests pass. After the tests finish, the containers stop and are removed automatically.
Summary
Testing with real Kafka and MySQL instances gives you more confidence in the correctness of your code than mocks or embedded alternatives. The Testcontainers library manages the container lifecycle so that your integration tests run against the same services you use in production.
To learn more about Testcontainers, visit the Testcontainers overview.