Example: Testing & Other Data Formats

In this lesson, we'll discuss the testing with Kafka and the data format Avro.

Tests with embedded Kafka #

In a JUnit test, an embedded Kafka server can be used to analyze the functionality of the microservices. In this case, a Kafka server runs in the same Java Virtual Machine (JVM) as the test. Thus, it is not necessary to build up an infrastructure for the test, and consequently, there is no need to tear down the infrastructure again after the test.

This requires two things essentially:

  • An embedded Kafka server has to be started. With a class rule, JUnit can be triggered to start a Kafka server prior to the tests and to shut it down again after the tests. Therefore, a variable with @ClassRule must be added to the code.

Get hands-on with 1200+ tech skills courses.