The most simple way to test Kafka based applications or micro-services e.g. Read/Write during HBase/Hadoop or other Data Ingestion Pipe Lines
This repo used open-source lib zerocode-tdd for declarative style testing. Many flavours of HelloWorld samples are available to clone and run.
Please make sure you bring up Kafka in a Docker prior to running the tests.
Let's learn the most simple and efficient way of automated testing of Kafka applications. This is particulaly useful during:
Other HelloWorld examples, such as Spring boot app testing, Performance testing, Kotlin app testing etc.
For running the below test, please jump to the corresponding JUnit @Test.
@TargetEnv("kafka_servers/kafka_test_server.properties")
@RunWith(ZeroCodeUnitRunner.class)
public class KafkaProduceTest {
@Test
@JsonTestCase("kafka/produce/test_kafka_produce.json")
public void testProduce() throws Exception {
// No code needed here.
}
}
In the above code
test_kafka_produce.json
is the Test Case which contains the JSON step(s). See a sample below.kafka_test_server.properties
contains the "Broker" details and Producer/Consumer configs@RunWith(ZeroCodeUnitRunner.class)
is a JUnit custom runner to run the teste.g.
{
"scenarioName": "Simple Produce and Consume a record to-from a kafka topic",
"steps": [
{
"name": "produce_step",
"url": "kafka-topic:demo-topic1",
"operation": "produce",
"request": {
"records":[
{
"key": "${RANDOM.NUMBER}",
"value": "Hello World"
}
]
},
"assertions": {
"status" : "Ok"
}
},
{
"name": "consume_step",
"url": "kafka-topic:demo-topic1",
"operation": "consume",
"request": {
},
"assertions": {
"size": 1,
"records": [
{
"key" : "$NOT.NULL",
"value": "Hello World"
}
]
}
}
]
}
Now you can see the-
target
target/logs/test_logs.log
target/zerocode-junit-granular-report.csv
target/zerocode-junit-interactive-fuzzy-search.html
For quick reference only - See more eclipse keys
More keys - See more IntelliJ keys