Chapter 1. Testing microservices

 

This chapter covers

  • A brief background on microservices
  • The challenges of testing microservices
  • How service virtualization makes testing easier
  • An introduction to mountebank

Sometimes, it pays to be fake.

I started developing software in the days when the web was starting to compete with desktop applications in corporate organizations. Browser-based applications brought tremendous deployment advantages, but we tested them in almost the same way. We wrote a monolithic application, connected it to a database, and tested exactly like our users would: by using the application. We tested a real application.

Test-driven development taught us that good object-oriented design would allow us to test at much more granular levels. We could test classes and methods in isolation and get feedback in rapid iterations. Dependency injection—passing in the dependencies of a class rather than instantiating them on demand—made our code both more flexible and more testable. As long as we passed in test dependencies that had the same interface as the real ones, we could completely isolate the bits of code we wanted to test. We gained more confidence in the code we wrote by being able to inject fake dependencies into it.

1.1. A microservices refresher

1.2. The problem with end-to-end testing

1.3. Understanding service virtualization

1.4. Introducing mountebank

1.5. The service virtualization tool ecosystem

Summary

sitemap