Chapter 4. Microservices testing

 

This chapter covers

  • What types of testing do you need to consider?
  • Which tools are appropriate for microservices?
  • Implementing unit testing for microservices
  • Implementing integration testing for microservices
  • Using consumer-driven contract testing

Where to start! So many types and levels of testing can be implemented for anything. Complicating things further is that different people will likely have different points of view, specifically in regard to what the various types of testing should accomplish.

Let’s get on the same page with respect to the types of testing and create a common understanding of their meaning for us all! In this chapter, you’ll focus only on the types of testing that are relevant for our purposes. There are too many types of testing to cover them all; it’d become overwhelming.

Then you’ll use the admin service you created in chapter 2 to show the types of testing that can be performed with a microservice.

4.1. What type of testing do you need?

Three types of testing are covered in this chapter:

  • Unit testing is focused on testing the internals of your microservice.
  • Integration testing covers the entirety of your service, in addition to the way it interacts with external services, such as a database.
  • Consumer-driven contract testing deals with the boundary between a consumer of your microservice and the microservice itself, via a Pact document that defines the contract.

4.2. Unit testing

4.3. What is immutability?

4.4. Integration testing

4.5. Consumer-driven contract testing

4.6. Additional reading

4.7. Additional exercises

Summary