The microservice architecture paradigm is constructing an application by breaking it into small independent services. Each operates in its process and communicates with the others through a most typically HTTP API. These services are entirely autonomous in their deployment and operation.
Testing a microservice architecture has its own challenges and strategies which we will outline in this blogpost.
Microservices Architecture Testing: What You Need to Know
Unit tests
The internal functionality of a microservice should be covered with unit tests that test individual functions, classes or methods in isolation.
Contract tests
The exposed API should be covered by contract tests. These ensure that the API behaves as specified. There are two forms of contract tests:
- Consumer driven: The consumer provides a set of tests with a defined output. The service owner executes the tests to make sure functionality does not break for a consumer.
- Producer driven: The microservice provides tests that emulate API requests potential consumers of the service can make.
Integration tests
Integration testing involves two or more microservices and focuses on the interaction between those services and not on the desired behavior. They test if the services can communicate with each other, third-party services and databases on an interface level.
Component tests
In contrast to integration tests component tests focus on the behavior of two or more services that form a business function. They are therefore a form of acceptance test.
End-to-end tests (E2E)
After ensuring that every service and every component of the system does what it should do E2E Tests make sure that the whole application fulfills the business objectives.
With microservices, you can usually spin up an environment that is very close to production and implement test cases that map the whole user journey.
Conclusion
Microservice architectures introduce a lot of operational complexity at the benefit of scalability and independent deployability. Testing becomes easier for each microservice in isolation while testing the whole user journey needs a more complex setup. Depending on the use case it may be enough to implement unit, contract, and component tests. If an E2E and/or integration approach is chosen a dedicated team QA team often is needed.