TV Test Pattern - Microservices Testing Concept
PHOTO: Shutterstock

Out of 353 “senior development stakeholders” surveyed by Dimensional Research Inc., 86% said microservices will become the default architecture within five years.

Indeed, microservices possess a number of advantages over traditional monolithic systems. But when it comes to testing, there are some roadblocks that microservices architectures need to overcome.

Why Testing Microservices Is a Challenge

When transitioning to a microservice architecture many teams do not plan properly. “For testing [microservices], I see teams run into issues where they haven't fully planned out which testing strategies they want to use. This especially happens when teams are brand new to microservices,” said Jake Lumetta, CEO and co-founder of ButterCMS.

Another challenge, according to Arijit Mukherji, CTO at Signal FX, is developers are not too sure how much time they should allocate to testing microservices. “Developers spend good chunks of time writing code then pass it on to QA teams that test this code and after a slew of back-and-forth for bug fixes etc., the operations teams pick the code to deploy it. This means releasing new software can take an exorbitant amount of time,” said Mukherji.

Additionally, there is a high likelihood that each microservice has been developed using a different framework and programming language, leading to individual services having their own runtime. This creates a complicated infrastructure for testing. “For a development team to get the most value out of tests, they need to be able to detect failures at every stage: right after making a code change, while code is being reviewed, after integrating changes from multiple developers, and right before deployment,” said David Strauss, CTO and co-founder of Pantheon. “Because microservices may rely on a variety of runtimes [such as] Node.js, Go and Java, providing the infrastructure for testing at each stage can be a challenge.”

Therefore the main challenge is to “aggregate all these [different testing frameworks] in a way that you can automate certain tasks — such as releasing a new version of a service that depends not on one, but on a set of microservices developed by different teams,” said Amir Samary, manager of solution architecture at InterSystems.

So how exactly should microservices testing be carried out? Here's what our experts said. 

Related Article: Understanding the Differences Between Microservices, Monoliths, SOA and APIs

1. Adopt a DevOps Culture

DevOps combines the responsibilities of developers and operators to enable the software to be continuously improved based on current consumer demands.

“One proposed solution to help quicken the software development lifecycle and enable the adoption of a DevOps culture is from a practice where software engineers are responsible for ensuring the quality of their code by using testing services provided from other team members,” Mukherji said.

2. Break Up the Test Framework

Mukherji noticed that despite the rapid adoption of microservices, many development teams are using a single test framework. Mukherji advised teams to break their testing framework into “micro test harnesses.”

“It is basically counterintuitive for organizations to use these monolithic [test] frameworks that are riddled with bugs and overloaded with huge amounts of code to test microservices. If engineers can break up a monolithic architecture into microservices, then why not break up a large single test framework into micro test harnesses?” Mukherji said.

3. Test for Scalability

One of the main advantages of a microservices architecture is that you are able to scale each service independently, without affecting the other services that are loosely coupled to the microservice. However, according to Samary, this needs to be tested regularly.

“You must make sure you are testing [your microservices] for volumes and that you can scale. So you must find a tool to generate this volume testing as well so you can be sure you can scale and fulfill the contract,” said Samary

4. Test for Communication Between the Services

A microservice architecture can only work if the services are able to communicate with each other. Andreas Grabner, DevOps activist at Dynatrace, advised brands to “test a microservice in isolation to validate that its API endpoints are working correctly” as well as “interactions with dependent services to validate service-to-service contracts.”

Grabner added that you also need to ensure the APIs you are using in your microservice architecture are working.

Related Article:  The Benefits and Challenges of Microservices Architecture

5. What Tools Should Developers Use to Test Microservices?

For successful testing of microservices, developers need to have access to the relevant tools that help to test the endpoints of microservices and can be automated into the CI/CD pipeline. “It’s also important to leverage tools that provide scripting languages that developers like to use. The goal is that developers need to also write their own tests, and therefore the learning curve of a testing framework or script language must be minimal,” said Grabner.

Grabner also advised brands to invest in monitoring tools that can provide insights into what is happening inside the microservice. “It’s important to invest in proper monitoring for your microservices because testing alone only gives you feedback seen by the testing tool. Monitoring provides insights into what is happening inside a service, between service interactions and how it impacts end-to-end business transactions,” said Grabner.