Chapter 4.  Testing and Quality Control

In this chapter, we will look at the different testing methodologies that you can use before, during, and after the development process. As you will know, testing your application avoids future issues and gives you a better project overview.

The importance of using tests in your application

It is very important to use testing in our application because these steps can avoid (or at least reduce) future problems or errors that can appear as we are humans and can make mistakes during the development process or because the structure of the project is not correct or even the understanding of the developer does not match the requirements of the customer.

The testing process will help improve the code quality and understanding of the functionalities, do regression testing in order to avoid the inclusion of old issues in continuous integration and reduce the time taken to finish the project.

Testing is used to reduce the fails or errors in our application. Development teams spend a lot of time doing bug fixing and, depending on the moment of the discovery of the bugs, the impact can be bigger or smaller. The following image shows the relative cost of bug fixing related to the stage of the development:

The importance of using tests in your application

The reason for using testing methodologies in development is that we can find errors in our code in the early steps of the development so that we will spend less time doing bug fixing.

Testing in microservices

The challenge of testing an application based on microservices is not in the testing of every single microservice, but on the integration and data consistency. An application based on microservices will need a better understanding of the architecture of microservices and their workflow by the developers to be able to use testing on it. This is because it is necessary to check the information and also the functionality of every microservice at all the points of communication between the microservices.

The testing to use on microservices are as follows:

  • Unit testing: In all the applications based on microservices or even in a monolithic one, it is necessary to use unit testing. Using it, we will check the necessary functionality of the methods or code modules.
  • Integration testing: Unit testing only checks the isolated components, so we also need to check the behavior between methods. We will check the behavior between methods of the same microservice using integration testing, so the calls between microservices will need to be mocked.
  • API tests:The microservices architecture depends on the communication between them. For each microservice, it is necessary to establish an API; this is like a contract to use that microservice. With this kind of test, we will check that the contract is working for each microservice and all the microservices are working with each other.
  • End-to-end tests:These guarantee the application quality without any mockup method or call. A test will be run to assess the functionality between all the required microservices. There are some rules to avoid problems during these tests:
    • End-to-end tests are difficult to maintain, so only test the most important functionalities; the rest of them use unit testing
    • The user functionalities can be tested by simulating calls to the microservices
    • It is necessary to keep a clean environment to test it because the tests are very dependent on the data, so a previous test can manipulate the data and then, the next test

Once we know how to proceed with testing our application based on microservices, we will look at some strategies to do so during development.

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

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