Introduction
One embedded broker for the whole suite.
Wiretap gives Spring Boot tests a single shared Kafka broker instead of creating a fresh one for every test class. Predictable setup, less context churn, fewer intermittent failures.
Overview
If you're relying on @EmbeddedKafka across a larger suite, you've probably seen the same failure pattern: tests pass on their own but fail when the full suite runs, CI shows disconnects with no obvious change, and repeated broker start-up makes failures noisy. The root cause is rarely Kafka itself — it's the cost of spinning up multiple embedded brokers and tearing them down repeatedly inside the same JVM.
This library starts one EmbeddedKafkaKraftBroker per JVM, injects spring.kafka.bootstrap-servers automatically, creates topics from configuration and annotation attributes, supports YAML or JSON topic files with per-topic partition counts and schema validation, clears records and consumer groups between tests, and registers the broker as a Spring bean so existing test wiring still works.
From 5.0, the same harness also runs against a broker you already have (pass-through mode) and can put a topic into a declared starting state before every test (seeding).
@SpringBootTest
@EnableWiretapKafkaBroker
class OrderServiceTest {
@Autowired
private KafkaTemplate<String, OrderEvent> kafkaTemplate;
@Test
void shouldPublishOrderEvent() throws Exception {
var order = new OrderEvent("order-123", "Widget", 2);
kafkaTemplate.send("orders", order.getId(), order).get();
}
}Documentation
Installation
Add the test dependency and check Java, Spring Boot, and Spring Kafka requirements.
ReadQuick start
Declare topics, add @EnableWiretapKafkaBroker, and run a real integration test.
ReadConfiguration
Property keys, annotation attributes, topic files, mock Schema Registry.
ReadSeeding
NewDeclare the records a test starts from in a fixture file, placeholders included.
ReadPassthrough mode
NewRun the same suite against Testcontainers or a broker you already have.
ReadBean overrides
Keep your production Kafka beans. Bootstrap is rewritten in place.
ReadShare groups
NewTest Kafka queue consumers (KIP-932) next to classic listeners: readiness by kind, the earliest start-offset default, and order-free assertions.
ReadMigration guide
From spring-kafka-test-utils 4.x to Wiretap 5.0, and from @EmbeddedKafka.
ReadFluent assertions
NewRecord, topic, listener readiness, snapshots, and choreography assertions.
ReadAPI reference
Lifecycle, publishing, reading, async coordination, assertions API.
Read
Requirements
- Java 17+
- Spring Boot 4.0+
- Spring Kafka 4.0+
- JUnit Jupiter