8 Automated testing for microservices

 

This chapter covers

  • Automated testing of microservices
  • Unit testing and integration testing with Jest
  • End-to-end testing with Cypress
  • Adding automated testing to your continuous delivery pipeline

To this point in the book while building microservices, we have tested our code manually. In this chapter, though, we’ll shift up a gear and learn how to apply automated testing to our microservices.

So far, we have primarily done our testing by running our code and visually inspecting the output. In various chapters, we used our web browser, the output from the command line, or changes in the local filesystem to check the results of our code. In other chapters, we used more specific tools like Robo3T in chapter 3 or the RabbitMQ dashboard in chapter 5.

Methods of manual testing are many and varied. I want you to know that manual testing is OK and perfectly valid. You should start with manual testing and continue with it until you are comfortable enough to use automated testing, and your product is well enough understood that it’s worth making the investment in that. I can recommend tools for manual testing like Postman or REST Client for Visual Studio Code. These will help you to manually test your REST APIs.

8.1 New tools

8.2 Getting the code

8.3 Testing for microservices

8.4 Automated testing

8.5 Testing with Jest

8.5.1 Why Jest?

8.5.2 Setting up Jest

8.5.3 The math library to test

8.5.4 Your first Jest test

8.5.5 Running your first test

8.5.6 Live reload with Jest