In the previous section, we discussed how testing a microservice is a complex and challenging job. In this section, we will discuss some points that will indicate how conducting various tests could help us overcome these challenges:
- A unit test framework, such as Microsoft Unit Testing Framework, provides a facility to test individual operations of independent components. To ensure that all the tests pass and that a new functionality or change does not break anything (if any functionality breaks down, then the related unit test would fail), these tests can be run on every compilation of code.
- To make sure that responses are consistent with the expectations of the clients or consumers, consumer-driven contract testing can be used.
- Services use data from an external party or from other services, and they can be tested by setting up the endpoint of the services that are responsible for handling the data. Then we can use a mocking framework or library such as moq to mock these endpoints during the integration process.