9 Automated testing for microservices

 

This chapter covers

  • Using automated testing with microservices
  • Unit testing and integration testing with Jest
  • End-to-end testing with Playwright

To this point in the book, while building microservices, we’ve 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’ve primarily done our testing by running our code and visually inspecting the output. Methods of manual testing are many and varied. I want you to know that manual testing is okay, to a point. You should start with manual testing and continue with it until you’re comfortable enough to use automated testing.

Your product should also be well enough understood that it’s worth investing in automated testing. Doing automated testing for minimum viable products (MVPs) or prototypes is often a waste of time and slows down development—in those cases, manual testing is adequate.

9.1 New tools

9.2 Getting the code

9.3 Testing for microservices

9.4 Automated testing

9.5 Automated testing with Jest

9.5.1 Why Jest?

9.5.2 Setting up Jest

9.5.3 The math library to test

9.5.4 Our first Jest test

9.5.5 Running our first test

9.5.6 Live reload with Jest

9.5.7 Interpreting test failures

9.5.8 Invoking Jest with npm

9.5.9 Populating our test suite

9.5.10 Mocking with Jest