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 |