Hello Kafka Stream Testing Save

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

Project README

Kafka Testing Hello World examples

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:

  • Micro-Services involving REST and Kafka
  • Read/Write during BigData store e.g. HBase/Hadoop
  • any other Data Pipe Lines
Try-at-home examples and much more(click to exapnd)

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 test

e.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-

  • Reports @ target
  • Logs @ target/logs/test_logs.log
  • Test coverage CSV Report @ target/zerocode-junit-granular-report.csv
  • Test coverage Chart @ target/zerocode-junit-interactive-fuzzy-search.html
  • More reports

IDE References:

Eclipse(General key-board shotcuts):

For quick reference only - See more eclipse keys

  1. Open a matching java file -> Ctrl + Shift + R
  2. Open a matching JSON file -> Ctrl + Shift + R
  3. To navigate to file -> Ctrl + Click
  4. Clik a JSON file and navigate to it's JUnit Test -> Alt+Cmd+G(Mac: ++G), Windows(Alt+Ctrl+G)

IntelliJ(General key-board shotcuts):

More keys - See more IntelliJ keys

  1. Open a matching java file -> Ctrl + n
  2. Open a matching JSON or XML file -> Ctrl + Shift + n
  3. To navigate to file -> Ctrl + Click
  4. Usage/invocation of a JSON file or Java File or Java method/variable etc -> Alt + F7
Open Source Agenda is not affiliated with "Hello Kafka Stream Testing" Project. README Source: authorjapps/hello-kafka-stream-testing

Open Source Agenda Badge

Open Source Agenda Rating