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).

OrderServiceTest.java
@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

Requirements

  • Java 17+
  • Spring Boot 4.0+
  • Spring Kafka 4.0+
  • JUnit Jupiter