chapter seven

7 Testing Microservices

 

This chapter covers

  • Understanding the motivation behind testing
  • Test strategies like unit testing, integration testing, and end-to-end testing
  • Testcontainers usage in test automation
  • Calculating and viewing the test Coverage for test suites
  • Understanding Test Pyramid

Microservice Architecture encourages you to write minimal services, which means they can be easily testable as a unit. For example, while testing Order Service, the only context you need to focus on is Order. To test Order Service, you have two alternatives in high-level: Manual Testing and Automated Testing.

With manual testing, you must run actual service and dependent services to test the entire flow. As you can guess, it might be a time-consuming operation compared to testing backed by a machine. This inefficient testing methodology will also slow down your software delivery. However, with automated testing, you can get fast feedback from your implementation since you don’t need to wait until you finish and test the entire system.

7.1 Testing Pyramid

7.2 Testing with Unit Test

7.2.1 System Under Test

7.2.2 Test Workflow

7.2.3 Working with Mocks

7.2.4 Implementing Mock

7.2.5 Automatic Mock Generation

7.3 Integration Test

7.3.1 Test Suite Preparation

7.3.2 Working with Test Containers

7.4 End-to-End Tests

7.4.1 Specifications

7.4.2 Understanding Docker Compose Service Definitions

7.4.3 End-to-End Test folder structure

7.4.4 Database Layer

7.4.5 Payment Service Layer

7.4.6 Order Service Layer

7.4.7 Running Tests Against Stack

7.5 Test Coverage

7.5.1 Coverage Information