TestOutputTopic is a Kafka Streams test utility that represents a topology's output topic. Create it through TopologyTestDriver with the exact topic name used by the topology, plus key and value deserializers that convert serialized output back into objects for assertions. section 14.1.3 section 14.2
Listing 14.11 Building the TopologyTestDriver and input and output topics
try (TopologyTestDriver driver =
new TopologyTestDriver(yellingTopology)) { #1
TestInputTopic<String, String> inputTopic = #2
driver.createInputTopic("src-topic",
stringSerializer,
stringSerializer);
TestOutputTopic<String, String> outputTopic = #3
driver.createOutputTopic("out-topic",
stringDeserializer,
stringDeserializer);
Use the setup listing to see TestOutputTopic paired with TestInputTopic inside a TopologyTestDriver. section 14.1.3
After records pass through TestInputTopic, read the produced results from TestOutputTopic and compare them with expected values. Choose a reader according to the assertion: readValue or readValuesToList for values, readKeyValue or readKeyValuesToList for ordered key-value records, readRecord or readRecordsToList when timestamps or headers matter, and readKeyValuesToMap for the latest result per key. section 14.1.3 section 14.1.4
Validate a topology's output
Send values through the input topic, derive the expected uppercase values, read the output list, and assert equality. The output topic captures the topology's serialized results as deserialized Java values. section 14.1.3 section 14.1.3
Listing 14.12 Sending records through the topology and validating results
List<String> inputValues = List.of("if you don't eat your meat", #1
"you can't have any pudding!",
"How can you have any pudding",
"if you don't eat your meat!" );
inputTopic.pipeValueList(inputValues); #2
List<String> expectedOutput = inputValues.stream()
.map(String::toUpperCase)
.toList(); #3
List<String> actualOutput = outputTopic.readValuesToList(); #4
assertThat(actualOutput, equalTo(expectedOutput)); #5
Use the validation listing for a complete pipe, expected-output, read, and assertion sequence. section 14.1.3
For stateful or time-driven topologies, TestOutputTopic also exposes intermediate or final behavior: read ordered updates, collect the latest value for each key, inspect queue size, or read results after timestamps advance and suppressed windowed output is emitted. section 14.1.4 section 14.1.4

