Skip to main content

Topics : Given input topic / Given output topic

Topics are the entry points for producers (input) and consumers (output). You must declare a topic before referencing it in When or Then steps.


Given input topicโ€‹

Declares one or more Kafka topics that your test will produce messages to.

Given input topic
| topicName | topicAlias | namespace | namespaceAlias |
| orders-in | orders-in | | |
ColumnTypeRequiredDescription
topicNamestringโœ…Physical Kafka topic name (namespace prefixed automatically)
topicAliasstringโœ…Short name used in When steps
namespacestringโŒOverride namespace for this topic
namespaceAliasstringโŒReference a named namespace declared in Given namespaces

Given output topicโ€‹

Declares one or more Kafka topics that your test will consume and assert messages from.

Given output topic
| topicName | topicAlias | namespace | namespaceAlias |
| orders-out | enriched | myapp | |
ColumnTypeRequiredDescription
topicNamestringโœ…Physical Kafka topic name (namespace prefixed automatically)
topicAliasstringโœ…Short name used in Then steps
namespacestringโŒOverride namespace for this topic
namespaceAliasstringโŒReference a named namespace declared in Given namespaces
Input โ‰  Output

KTestify enforces topic type at the context level. Passing an INPUT topic to a Then step throws a ConsumerException immediately. This prevents accidental off-by-one topic confusion.


Multiple topics in one declarationโ€‹

You can declare multiple topics in one step by adding extra DataTable rows:

Given output topic
| topicName | topicAlias |
| orders-out | orders |
| audit-out | audit |

Typical backgroundโ€‹

Background:
Given namespace
| namespace |
| myapp |
Given input topic
| topicName | topicAlias |
| orders-in | orders-in |
Given output topic
| topicName | topicAlias |
| orders-out | orders-out |