14 Testing

 

This chapter covers

  • Understanding the difference between unit and integration testing
  • Testing Kafka producers and consumers
  • Creating tests for Kafka Streams operators
  • Writing tests for a Kafka Streams topology
  • Developing effective integration tests

So far, we’ve covered the components for building an event streaming application: Kafka producers and consumers, Kafka Connect, and Kafka Streams. But I’ve left out another crucial part of this development until now: how to test your application. One of the critical concepts we’ll focus on is placing your business logic in standalone classes entirely independent of your event streaming application because that makes your code much more accessible to test. I expect you’re aware of the importance of testing, but I’d like to cover the top two reasons testing is just as necessary as the development process itself.

First, as you develop your code, you’re creating an implicit contract of what you and others can expect about how the code performs. The only way to prove that the application works is by testing it thoroughly. You’ll use testing to provide a good breadth of possible inputs and scenarios to ensure everything works appropriately under reasonable circumstances. The second reason you need comprehensive testing is that it helps you deal with the inevitable changes that occur with software. A rigorous set of tests gives you immediate feedback when the new code breaks the expected behaviors.

14.1 Understanding the difference between unit and integration testing

14.1.1 Testing Kafka producers and consumers

14.1.2 Creating tests for Kafka Streams operators

14.1.3 Writing tests for a Kafka Streams topology

14.1.4 Testing more complex Kafka Streams applications

14.1.5 Developing effective integration tests

Summary