Testing evaluates expected behavior across defined inputs and scenarios, proving an application's contract and catching regressions during change or refactoring. Fast, repeatable tests belong in continuous integration; Kafka applications should keep business logic independent of event-streaming infrastructure so it can be tested directly. section 14.0
Unit tests isolate a specific component, usually method-level logic, and use mocks to supply inputs and validate results without real external services. Integration tests instead run real connected components to verify that the system works together; they are slower, so they should be fewer. section 14.1
Test a producer-consumer application without a broker
A currency-exchange client consumes non-US transactions, converts each amount to US dollars, and produces the result. Accept Consumer and Producer interfaces in its constructor, substitute MockConsumer and MockProducer, schedule setup and input-record tasks, then schedule close to end the polling loop. Inspect producer history and assert the converted transactions match expectations. section 14.1.1
For Kafka Streams, test mappers, filters, aggregators, and punctuators as concrete units, then exercise the complete topology with TopologyTestDriver. Create test input and output topics, pipe records through the extracted production topology, read output, and compare it with expected values. Supply timestamps when window advancement matters. section 14.1.3 section 14.2
Use integration tests when a real broker is necessary. Testcontainers manages the Kafka container lifecycle; with the JUnit 5 extension, making the container field static can avoid starting a new container for every test in a class. section 14.2




















































