Skip to main content

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 |
ColumnTypeRequiredDefaultDescription
namespacestringโœ…โ€”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 |
ColumnTypeRequiredDefaultDescription
namespacestringโœ…โ€”Namespace prefix
namespaceAliasstringโœ…โ€”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 | | |
ColumnTypeRequiredDefaultDescription
topicNamestringโœ…โ€”Physical topic name (namespace prepended)
topicAliasstringโœ…โ€”Alias for use in When steps
namespacestringโŒConfig defaultOverride namespace for this topic
namespaceAliasstringโŒโ€”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 | |
ColumnTypeRequiredDefaultDescription
topicNamestringโœ…โ€”Physical topic name (namespace prepended)
topicAliasstringโœ…โ€”Alias for use in Then steps
namespacestringโŒConfig defaultOverride namespace for this topic
namespaceAliasstringโŒโ€”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 |
ColumnTypeRequiredDefaultDescription
absolutePathstringโœ…KTESTIFY_ASSETS_DIR / configAbsolute 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 |
ColumnTypeRequiredDefaultDescription
schemaNamestringโœ…โ€”Schema Registry subject name (prefix for schemaName-value)
schemaAliasstringโœ…โ€”Short alias
schemaVersionintegerโŒlatestSchema version to use

Actions โ€” When stepsโ€‹

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 |
ColumnTypeRequiredDefaultDescription
topicNamestringโœ…โ€”Topic name or alias (must be declared as INPUT)
filestringโœ…โ€”Payload file, relative to assets directory
recordKeystringโŒnullKafka record key
headerFilestringโŒโ€”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 |
ColumnTypeRequiredDefaultDescription
topicNamestringโœ…โ€”Input topic name or alias
filestringโœ…โ€”JSON payload file
schemaNamestringโŒTopicNameStrategySchema alias or name declared via Given schema
recordKeystringโŒnullKafka record key

And wait for {int} secondsโ€‹

Pauses execution.

And wait for 5 seconds
ParameterTypeRequiredDescription
{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 |
ColumnTypeRequiredDefaultDescription
scriptPathstringโœ…โ€”Path to the script file
scriptArgsstringโŒโ€”Comma-separated arguments

Fails if exit code โ‰  0.


Assertions : Then / And stepsโ€‹

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 |
ColumnTypeRequiredDefaultDescription
topicAliasstringโœ…โ€”Output topic alias
filestringโœ…โ€”Expected file path
expectedRecordKeystringโŒโ€”Filter by record key
consumerReadTimeoutintegerโŒConfig (30)Seconds to wait
consumerDeltaTimeintegerโŒ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 |
ColumnTypeRequiredDefaultDescription
topicAliasstringโœ…โ€”Output topic alias
filestringโœ…โ€”Expected file
lineintegerโœ…โ€”1-based line number
fromintegerโœ…โ€”Start char index (inclusive)
tointegerโœ…โ€”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 | |
ColumnTypeRequiredDefaultDescription
topicAliasstringโœ…โ€”Output topic alias
filestringโœ…โ€”Expected XML file
excludedElementsstringโŒโ€”Comma-separated element names to skip
expectedRecordKeystringโŒโ€”Filter by record key
consumerReadTimeoutintegerโŒConfig (30)Seconds to wait
consumerDeltaTimeintegerโŒ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() |
ColumnTypeRequiredDefaultDescription
topicAliasstringโœ…โ€”Output topic alias
filestringโœ…โ€”Expected values file (one per line)
xpathExpressionsstringโœ…โ€”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 |
ColumnTypeRequiredDefaultDescription
topicAliasstringโœ…โ€”Output topic alias
filestringโœ…โ€”Expected JSON file
excludedKeysstringโŒโ€”Comma-separated Avro field names to exclude
expectedRecordKeystringโŒโ€”Filter by record key
consumerReadTimeoutintegerโŒConfig (30)Seconds to wait
consumerDeltaTimeintegerโŒ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 |
ColumnTypeRequiredDefaultDescription
topicAliasstringโœ…โ€”Output topic alias
keystringโœ…โ€”Avro field name
valuestringโœ…โ€”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 |
ColumnTypeRequiredDefaultDescription
topicAliasstringโœ…โ€”Output topic alias
expectedRecordsCountintegerโœ…โ€”Exact number of records to collect
filesstringโœ…โ€”Comma-separated expected file paths
consumerReadTimeoutintegerโŒConfig (30)Seconds to wait for all records
consumerDeltaTimeintegerโŒ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 |
ColumnTypeRequiredDefaultDescription
topicAliasstringโœ…โ€”Output topic alias
expectedRecordsCountintegerโœ…โ€”Exact number of records to collect
filesstringโœ…โ€”Comma-separated expected JSON file paths
excludedKeysstringโŒโ€”Avro field names to exclude from all records
consumerReadTimeoutintegerโŒConfig (30)Seconds to wait for all records
consumerDeltaTimeintegerโŒ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 |
ColumnTypeRequiredDefaultDescription
topicAliasstringโœ…โ€”Output topic alias
topicTypestringโœ…โ€”raw or avro
consumerReadTimeoutintegerโŒConfig (30)Seconds to wait
consumerDeltaTimeintegerโŒ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 stepraw topicsavro 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