Integration testing

Unit test cases perform test checks and verify the code, but they only verify the inside logic of that particular part of the code, not the dependent module. For example, if service layer A method depends on service layer B method, and we are writing test cases for service A, we will mock service B. In this case, service layer A passes all its test cases and the same happens with service layer B. So, test cases for both service layers run perfectly fine individually, but not with each other. So, the verification of service layers is done on an individual level, but communicating with other service methods is also tested in the case of microservices.

This is where we introduce integration testing. It ensures that the all the different layer components work perfectly together and provide the expected results. For example, the data layer is getting data from the database, and the service layer is hitting the database layer and converting data into the desired format to send back to the user. In an ideal scenario, a service layer has its own unit test cases, as a service layer has dependencies on the data layer, so the data layer is mocked in service layer test cases. As service layer test cases only focus on service layer code, there could be a test case where the service layer sends some input to the data layer which is not acceptable for the data layer in reality. The reason could be anything and completely independent of service layer logic, say perhaps due to a validity fail in the data layer. But as we have mocked data layer in test cases, it will accept and respond with a predefined response. This results in successful test completion of the service layer. However, in the test case, it will fail, as the value sent by the service layer is not acceptable for the data layer method.

In the same way, there could also be external service calls in the system, as the microservice architecture includes many services running together. So you might ask whether testing with external services (external to your service code) should be included in testing. I would say no; any external service should be mocked at this stage. As a developer, you are not responsible for other people's code. Although some of you may not agree with me on not including external service in integration testing, I feel that it is a part of end-to-end testing, which we will cover in a later section.

In integration tests, the tester or developer is responsible for the entire subsystem test case -not just a small portion of the code. It targets the whole module. So the impact of these types of test cases is more than that of unit test cases, as they try to analyze the behavior of the entire subsystem. They interact with peer methods or layers in a service to make sure that they communicate in the way they are supposed to.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset