Levels of Testing

We talked about different levels of testing that can be done when we create an application that uses Microservices. Let's take an example to clarify the difference between different types of testing and how useful each is. Say we have a form that lets the user enter employee details that get saved to a database and a success message is returned to the calling client. Additionally, say we use a layered design, with Controller, Service, Business, and Data.

The following diagram should make the design clear:

  • Unit Testing: Each class and each method is a unit in itself and can be tested independently. For example, say we take a look at the business layer, which might have many classes. We will take each class, and then try to test each method. In an ideal world, we would test each unit independently, but this might be time-consuming. So, based on time availability, it might make sense to understand core areas of your application and implement unit testing for those.
  • Integration Testing: Most of the time, our services cannot work in isolation. In the preceding example, our service is actually talking to a database. We need to test whether our service will work when the database is available and able to handle cases when the database is not responding or is slow.
  • Service Testing: Here we will focus on the service as a whole. We might want to mock any external dependencies, but we will make sure all the code that is part of our service  all the layers  should be tested.
  • End-to-end Testing: This includes testing from the first layer  the UI  until the last layer  the database.

Putting it all together, the following diagram should give you a clearer picture about what different levels of testing indicate:

The preceding markings should help you visualize the different layers of testing.

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

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