Step Reference
Complete catalogue of every KTestify step. All DataTable columns are listed with their type, whether they are required, the default value (if any), and an inline example.
Background : Given stepsโ
Given namespaceโ
Declares a single namespace prefix applied to all topic names.
Given namespace
| namespace |
| myapp |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
namespace | string | โ | โ | Namespace prefix (e.g. myapp, com.example) |
Given namespacesโ
Declares multiple named namespace prefixes.
Given namespaces
| namespace | namespaceAlias |
| myapp.input | input-ns |
| myapp.audit | audit-ns |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
namespace | string | โ | โ | Namespace prefix |
namespaceAlias | string | โ | โ | Alias referenced in topic declarations |
Given input topicโ
Declares one or more Kafka topics as producers (INPUT type).
Given input topic
| topicName | topicAlias | namespace | namespaceAlias |
| orders-in | orders-in | | |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
topicName | string | โ | โ | Physical topic name (namespace prepended) |
topicAlias | string | โ | โ | Alias for use in When steps |
namespace | string | โ | Config default | Override namespace for this topic |
namespaceAlias | string | โ | โ | Reference a Given namespaces alias |
Given output topicโ
Declares one or more Kafka topics as consumers (OUTPUT type).
Given output topic
| topicName | topicAlias | namespace | namespaceAlias |
| orders-out | enriched | myapp | |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
topicName | string | โ | โ | Physical topic name (namespace prepended) |
topicAlias | string | โ | โ | Alias for use in Then steps |
namespace | string | โ | Config default | Override namespace for this topic |
namespaceAlias | string | โ | โ | Reference a Given namespaces alias |
Given assets directoryโ
Sets the base directory for all relative file paths in the scenario.
Given assets directory
| absolutePath |
| src/test/resources/assets |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
absolutePath | string | โ | KTESTIFY_ASSETS_DIR / config | Absolute or project-relative path |
Given schemaโ
Declares an Avro schema for use in Avro producer/consumer steps.
Given schema
| schemaName | schemaAlias | schemaVersion |
| Order | order | 1 |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
schemaName | string | โ | โ | Schema Registry subject name (prefix for schemaName-value) |
schemaAlias | string | โ | โ | Short alias |
schemaVersion | integer | โ | latest | Schema version to use |
Actions โ When stepsโ
Producer and script steps below accept multiple DataTable rows, executed sequentially in order. Producer steps additionally require every row to resolve to the same physical topic (TopicMismatchException otherwise). See Multi-row DataTables for full details.
When record from file is sentโ
Produces a raw String message to a Kafka input topic.
When record from file is sent
| topicName | file | recordKey | headerFile |
| orders-in | payload.json | key-001 | headers.json |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
topicName | string | โ | โ | Topic name or alias (must be declared as INPUT) |
file | string | โ | โ | Payload file, relative to assets directory |
recordKey | string | โ | null | Kafka record key |
headerFile | string | โ | โ | JSON file of Kafka headers {"name":"value"} |
When record from file based on schema is sentโ
Produces an Avro-serialised message.
When record from file based on schema is sent
| topicName | file | schemaName | recordKey |
| orders-in | order.json | Order | ord-001 |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
topicName | string | โ | โ | Input topic name or alias |
file | string | โ | โ | JSON payload file |
schemaName | string | โ | TopicNameStrategy | Schema alias or name declared via Given schema |
recordKey | string | โ | null | Kafka record key |
And wait for {int} secondsโ
Pauses execution.
And wait for 5 seconds
| Parameter | Type | Required | Description |
|---|---|---|---|
{int} | integer | โ | Seconds to pause |
When script is executed / And execute scriptโ
Runs a shell script.
When script is executed
| scriptPath | scriptArgs |
| ./scripts/reset.sh | arg1,arg2 |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
scriptPath | string | โ | โ | Path to the script file |
scriptArgs | string | โ | โ | Comma-separated arguments |
Fails if exit code โ 0.
Assertions : Then / And stepsโ
Every single-record assertion step below (all except the two batch steps) accepts multiple DataTable rows, validated sequentially in order, provided every row targets the same physical topic (TopicMismatchException otherwise). All rows in the same step share one pinned referenceTimestamp so delta-time seek windows don't drift row-to-row. The batch steps (expected records from files / ...based on schema) remain strictly single-row. See Multi-row DataTables โ for full details.
Then expected record from fileโ
Raw file match, full value equality.
Then expected record from file
| topicAlias | file | expectedRecordKey | consumerReadTimeout | consumerDeltaTime |
| orders-out | expected.json | key-001 | 30 | 60 |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
topicAlias | string | โ | โ | Output topic alias |
file | string | โ | โ | Expected file path |
expectedRecordKey | string | โ | โ | Filter by record key |
consumerReadTimeout | integer | โ | Config (30) | Seconds to wait |
consumerDeltaTime | integer | โ | Config (60) | Seconds to seek back |
Then expected record should have fields matching from fileโ
Positional character field match.
Then expected record should have fields matching from file
| topicAlias | file | line | from | to |
| orders-out | expected.txt | 2 | 0 | 15 |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
topicAlias | string | โ | โ | Output topic alias |
file | string | โ | โ | Expected file |
line | integer | โ | โ | 1-based line number |
from | integer | โ | โ | Start char index (inclusive) |
to | integer | โ | โ | End char index (exclusive) |
Then expected record from file based on XMLโ
Structural XML comparison with optional element exclusions.
Then expected record from file based on XML
| topicAlias | file | excludedElements | expectedRecordKey |
| orders-out | expected.xml | ns:CreationDateTime | |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
topicAlias | string | โ | โ | Output topic alias |
file | string | โ | โ | Expected XML file |
excludedElements | string | โ | โ | Comma-separated element names to skip |
expectedRecordKey | string | โ | โ | Filter by record key |
consumerReadTimeout | integer | โ | Config (30) | Seconds to wait |
consumerDeltaTime | integer | โ | Config (60) | Seconds to seek back |
Then expected record based on XML should have fields matching from fileโ
XPath extraction + comparison.
Then expected record based on XML should have fields matching from file
| topicAlias | file | xpathExpressions |
| orders-out | expected.txt | //Weight[@unit='KG']/text(),//Sender/ID/text() |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
topicAlias | string | โ | โ | Output topic alias |
file | string | โ | โ | Expected values file (one per line) |
xpathExpressions | string | โ | โ | Comma-separated XPath expressions |
Then expected record from file based on schemaโ
Avro โ JSON file match with optional field exclusions.
Then expected record from file based on schema
| topicAlias | file | excludedKeys | expectedRecordKey | consumerReadTimeout |
| orders-out | expected.json | createdAt,eventId | ord-001 | 30 |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
topicAlias | string | โ | โ | Output topic alias |
file | string | โ | โ | Expected JSON file |
excludedKeys | string | โ | โ | Comma-separated Avro field names to exclude |
expectedRecordKey | string | โ | โ | Filter by record key |
consumerReadTimeout | integer | โ | Config (30) | Seconds to wait |
consumerDeltaTime | integer | โ | Config (60) | Seconds to seek back |
Then expected record based on schema should have fields matching from given valueโ
Assert specific Avro field values without a file.
Then expected record based on schema should have fields matching from given value
| topicAlias | key | value |
| orders-out | status | PROCESSED |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
topicAlias | string | โ | โ | Output topic alias |
key | string | โ | โ | Avro field name |
value | string | โ | โ | Expected field value |
Then expected records from filesโ
Raw batch, collect N records and match positionally against N files.
Then expected records from files
| topicAlias | expectedRecordsCount | files | consumerReadTimeout |
| orders-out | 3 | f1.json,f2.json,f3.json | 60 |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
topicAlias | string | โ | โ | Output topic alias |
expectedRecordsCount | integer | โ | โ | Exact number of records to collect |
files | string | โ | โ | Comma-separated expected file paths |
consumerReadTimeout | integer | โ | Config (30) | Seconds to wait for all records |
consumerDeltaTime | integer | โ | Config (60) | Seconds to seek back |
Then expected records from files based on schemaโ
Avro batch, collect N Avro records and match positionally.
Then expected records from files based on schema
| topicAlias | expectedRecordsCount | files | excludedKeys | consumerReadTimeout |
| orders-out | 2 | exp-1.json,exp-2.json | ts,eventId | 60 |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
topicAlias | string | โ | โ | Output topic alias |
expectedRecordsCount | integer | โ | โ | Exact number of records to collect |
files | string | โ | โ | Comma-separated expected JSON file paths |
excludedKeys | string | โ | โ | Avro field names to exclude from all records |
consumerReadTimeout | integer | โ | Config (30) | Seconds to wait for all records |
consumerDeltaTime | integer | โ | Config (60) | Seconds to seek back |
And record should appear in topicโ
Positive watcher, asserts at least one record is present.
And record should appear in topic
| topicAlias | topicType | consumerReadTimeout | consumerDeltaTime |
| orders-out | raw | 15 | 60 |
| Column | Type | Required | Default | Description |
|---|---|---|---|---|
topicAlias | string | โ | โ | Output topic alias |
topicType | string | โ | โ | raw or avro |
consumerReadTimeout | integer | โ | Config (30) | Seconds to wait |
consumerDeltaTime | integer | โ | Config (60) | Seconds to seek back |
And record should not appear in topicโ
Negative watcher, asserts no record appears within the timeout.
And record should not appear in topic
| topicAlias | topicType | consumerReadTimeout | consumerDeltaTime |
| orders-out | raw | 10 | 30 |
Same columns as record should appear in topic.
Matcher ร Topic type compatibilityโ
| Matcher step | raw topics | avro topics |
|---|---|---|
expected record from file | โ | โ use based on schema |
expected record from file based on XML | โ | โ not available |
expected record based on XML / XPath | โ | โ not available |
expected record from file based on schema | โ | โ |
expected record based on schema / field value | โ | โ |
expected records from files (batch) | โ | โ |
expected records from files based on schema (batch) | โ | โ |
record should (not) appear in topic | โ both | โ both |