My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more
Microservice Testing in 2020

Microservice Testing in 2020

Karl Kong's photo
Karl Kong
·Feb 11, 2020

So, you are on your microservice journey and the architecture is falling into place. Now only one tiny detail remains: how do we ensure quality of our microservices?

In this article I will go through some key concepts to testing your microservices in the most efficient way possible.

Unit tests 📦

Unit testing will just as before be the most important way to ensure that your service works as it should. Using frameworks for unit testing in your language you should be able to separate the different parts of your application into units and test them individually. Unit test make up the backbone of your testing strategy and it is possible to get very good functional coverage of your application using unit tests.

Integration tests 🔗

Integration tests historically will spin an environment up and make requests to the API to ensure that the responses are correct and nothing breaks. Typically you would run integration tests before each release as a quality gate to make sure that you do not break your APIs in production. This is quite easy if you have a monolith architecture. Simply spin up your only instance, run the tests, store the results and spin it down. When using microservices you suddently have a whole fleet of services which might be dependent on each other. This is something to keep in mind when architecting your services. You should always have an environment deployed where all your services that interact with each other are available to test them as a whole.

Service tests 🐕

Service tests are isolated tests run against your microservice that are independent of any external services that the test subject might be requesting. It might be hard to isolate a service completely since it almost always seems like we are dependent on something external but there are tools available to create mock APIs for testing. Using these tools you can create virtual versions of the external service that you call which behave just like you want them to. These can even be run locally to cut the need for an internet connection in your tests.

Load tests 🔥

Load testing is also something that becomes a bit more complex when running them against a fleet of services instead of a good old monolith. You need your fleet deployed and ready to accept a flurry of requests and you need the tools to determine where the bottlenecks are. Most cloud providers today have tools to monitor the load on your individual services such as AWS CloudWatch, Azure Monitor and Google Cloud Stackdriver. What is good is that you can scale each service individually according to the results of your load test to ensure that your application stays performant during usage spikes.

Chaos testing 🚒

Chaos testing is when you test what happens when some parts of your application fail. It might be the case that one of your microservices goes down. Does the rest of your microservices happily keep on running or do they fail miserably? There are a number of ways to do chaos testing to simulate failures in your environment. My recommendation is that you schedule a day where your developers try to take down parts of your fleet and carefully document the results and insights generated.

Conclusion

When testing microservices it is important to test both how they work together and how they work individually. To ensure that your application behaves gracefully even at peak load or during an outage is also important when developing high quality software.

Good luck with ensuring the best possible quality of your microservice application!