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 | | |
| Column | Type | Required | Description |
|---|---|---|---|
topicName | string | โ | Physical Kafka topic name (namespace prefixed automatically) |
topicAlias | string | โ | Short name used in When steps |
namespace | string | โ | Override namespace for this topic |
namespaceAlias | string | โ | 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 | |
| Column | Type | Required | Description |
|---|---|---|---|
topicName | string | โ | Physical Kafka topic name (namespace prefixed automatically) |
topicAlias | string | โ | Short name used in Then steps |
namespace | string | โ | Override namespace for this topic |
namespaceAlias | string | โ | 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 |