Testing Strategies in Microservices Architecture


Microservices is an approach of developing an application by splitting it into smaller services, where each module run in its own process and communicating with each other in a lightweight mechanism. These services are independently deployed and fully automated.

Microservices is a new term introduced which changed the architecture of the software development, moreover, it changes the working culture of the teams the way teams work together.

What are Microservices?

Microservices architecture divides the complex application into smaller modules. This provides a number of benefits over the monolithic architecture.

Microservices architecture deploys independently increase of the other modules. Microservices take this approach to independent services. With microservices, we will easily be able to adopt technology more quickly and understand how new advancements may help us.

In short, the Microservices architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with light weight mechanisms, often an HTTP resource API.

These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum of centralized management of these services, which may be written in different programming languages and use different data storage technologies.

Multiple services work together to form whole application, Services like service A, service B and service C work independently, and they collaborate and form the whole application. These services collaborate for the functioning of the application. These chunks of services are called Microservices.

Benefits of Microservices

The benefits of microservices are many and varied. Many of these benefits can be laid at the door of any distributed system. Microservices, however, tend to achieve these benefits to a greater degree primarily due to how far they take the concepts behind distributed systems and service-oriented architecture.

Deployed Independently

The most important benefit of the microservices is that it deployed independently of the other modules. In case if there is need to make changes to the module other modules remain unaffected. If one module stopped working then the application as a whole will not be affected only that one module will be affected.

Parallelize Development

The application which was broken down into smaller modules will be developed parallel to different developer work on different module and development of all the modules is parallel.

Need of Testing in Microservices

It is very important to test the microservices as to be very confident about the assumptions made for each service that it will do what is says to do. Testing of microservices is the first step for making the service reliable for the user. For the internal functional dependency of the microservices, the testing is more important for the service to stay strong.

Challenges of Microservices

Microservices architecture includes numerous tiny independently services which integrate with each other to form the whole application. These microservices interact with each other in the production environment for the functionality of the application, although these small microservices are very simple while communicating with each other there arise many complexities. As the granularity of the application increases.

Testing Strategies

It is essential that a microservice application is built with an awareness of how it can be tested. Having good test coverage gives you more confidence in your code and results in a better continuous delivery pipeline.

As this is a new architectural approach so require a new approach of doing automated testing and quality assurance. New approach divides the specific layer of tests. There is five layer of tests that are performed over microservices -

Unit Testing

Tests a single class or a set of closely coupled classes. These unit tests can either be run using the actual objects that the unit interacts with or by employing the use of test doubles or mocks.

In Unit testing, the smallest piece of testable software is tested in the application to determine whether it behaves as expected or not. Tests are typically run at the class level or around a small group of related classes. In unit testing, an important distinction is seen based on whether or not the unit under test is isolated from its collaborators.

Unit tests are usually written by the programmers using their regular tools - the only difference being the use of the same sort of unit testing framework.

There is further two types of testing in Unit Testing

Sociable Unit Testing

Solitary Unit Testing

**Sociable Unit Testing **- It focuses on testing the behaviour of modules by observing changes in their state. This treats the unit under test as a black box tested entirely through its interface.

**Solitary Unit Testing **- It looks at the interactions and collaborations between an object and its dependencies, which are replaced by test doubles.

Imagine you're testing an order class's price method. The price method needs to invoke some functions on the product and customer classes. If you like your unit tests to be solitary, you don't want to use the real product or customer classes here, because a fault in the customer class would cause the order class's tests to fail. Instead you use Test doubles for the collaborators.

Unit testing alone does not provide a guarantee about the behaviour of the system. Unit testing covers the core testing of the each module, however, there is no coverage of the test when these modules collaborate to work together to interact with the remote dependencies.

To be sure about each module work correctly with remote dependencies finer coarse-grained testing is required.

Integration Testing

Integration tests are used to test the communication between services. These tests are designed to test basic success and error paths over a network boundary.

Different components interact with each other for their functional dependency, while communicating with each other integration test verifies the communication paths between the components and detect the interface defects.

Continue Reading The Full Article At - XenonStack.com/Blog

All Rights Reserved

Let's register a Viblo Account to get more interesting posts.