Magazine

Testing Microservices: Challenges and Strategies

Posted on the 28 August 2019 by Testsigma @testsigmainc

The Microservice architectural approach is not recent in the software development world. Many companies and start-ups have switched to this architectural style and already reap its benefits. Automated Testing approaches and processes should adapt to the changes as well. In Testsigma we always keep up to date and we definitely can shed some light to the effective testing strategy for a microservices architecture. Want to make your  Automated Testing strategy the effective one? Let’s learn the ropes of the modern approaches in microservices testing!

What are the distinctive features of the Microservice architectural approach?

Before we switch to  Automated Testing details, it is worth defining the difference between a classical or monolithic application architecture and a more granular, a microservices one. Monolithic applications use a single code base with all modules implemented to make the whole system work. Therefore, DevOps use a single build system to build and run the software application.

Evidentially, there are some drawbacks to this architectural style:

  • Firstly, in the monolithic codebase, newcomers hardly understand how the system is implemented as the system looks monstrous. 
  • Secondly, with monoliths, an IDE very often becomes overloaded, the development process extends in time, code reviews become more complicated. 
  • Also, building a monolith application could be a strain as if some module changes, the whole system has to be re-deployed from scratch.
  • Big and heavy databases influence the whole system performance which is very important for end-users and businesses in particular.
  • In addition to that, such monolith systems have low fault tolerance which means that a cost to recover a system might be truly expensive.

All in all, a new revolutionary approach appeared when all these obstacles were analyzed. The microservice architecture was created as a solution to solve all the bottlenecks mentioned above. In a microservice style, as it can be guessed, small autonomous services build a single software solution. 

These services are independent in terms of the isolated codebase, self-sufficient deployment process, and data persistence. That means that if a service should be updated or fixed, there is no need to re-deploy the entire system. This approach helps to mitigate risks and reliably deliver the pieces of product to a customer. Moreover, the services can communicate with each other via API according to the pre-defined standards or contracts. 

How to build an automated testing process for a Microservice architecture?

Test automation, as well as manual testing, has to be properly planned at the very beginning as the incorrect approach can lead to non-beneficial processes and huge expenses. To avoid that we should, first of all, define our goals and to create a test strategy.


So, the steps to build a successful test automation process is the following:

  1. Ask your customer as much as possible regarding his expectations from test automation.
  2. Set quality goals and follow them when creating a test strategy and implementing tests themselves.
  3. Analyze which testing types will help you to achieve your quality goals.
  4. Stick to shift-left approach and adapt the whole development and testing process to it.
  5. Write tests taking into account the fact that according to the testing pyramid the cost of test increases starting from Unit tests. The amount of tests increases starting from the end-to-end tests. So, it is a bad approach to having a few unit tests and implement a bunch of UI tests. That contradicts the shift-left approach helps to identify the issues as earlier as possible.

For the effective test approach creation of a non-monolith architecture, we should bear in mind that the overall system and isolated web services function as expected. If we talk about testing strategy, the adjusted to the new architecture test pyramid can depict the balanced approach taking into account the following different testing types:

Testing microservices: Challenges and Strategies

So, to sum up, the test pyramid has a Unit test as a basic layer. They are implemented by developers. At this level, we verify that core functions work correctly in isolation from external references. The more unit test we have, at the earlier stages of the development process we can identify issues in the codebase and avoid a lot of further impact on the whole system. This approach is called shift-left: when the Automated Testing is shifted at the earlier stages in the timeline so the recovery is less expensive.

Above the component tests, there is a layer of component tests. For a microservice approach, component tests are tests that check service in autonomy.

Then, on the top of component tets, there are integration tests. This Automated Testing level is designed to verify the integration between external resources and the system layers.

The main difference from the classical pyramid is the layer of Contract tests. This testing type is destined for the communication between the services. It is a potential threat for the system when in isolation services work properly, but in combination with each other, fail to meet the quality expectations. These tests verify whether the interaction between services follows the contract rules or agreements established for them. There are several tools for contract testing, but the most reliable and effective ones are Spring Cloud Contract and Pact. So, it is up to you which suits you better.

Only when all other tests are implemented, it is high time to develop some end-to-end tests. However, before writing the test strategy, it is worth asking the customer about his expectations from test automation first.

Testsigma is built to assist to start your test automation as smoothly as possible. Now you can impress your customers with a cutting-edge automated testing approach!


Back to Featured Articles on Logo Paperblog