Melpomene - Fotolia

Tip

How to test microservices for functionality and compliance

If you're new to microservices testing practices, understand that traditional techniques won't work anymore. We examine how to approach four critical microservices tests.

Microservices work independently and communicate with other services via API calls. Testing these microservices-based applications is complicated, because the tester must be aware of not only a given service but also its dependencies -- and plan the test strategy accordingly.

Since a microservice is typically independently deployable and has its own data store, testers, whether the developer or a member of the QA team, need to treat each service as independently as possible. An effective microservices testing strategy puts the services in isolation to truly verify that the entire system is working properly.

There are four fundamental tests to perform on microservices: unit tests, integration tests, component tests and contract tests. Learn how to test microservices at each of these stages, and the tools that can support the testing strategy.

Unit testing

Unit testing validates that the code of each application component is in line with necessary business logic. This stage likely represents the largest number of individual test units you'll process, and is critically important in microservices-based applications.

Individual software component units don't follow a standard size -- they range from large blocks to a few lines of code. To test microservices accurately, you need to keep your test units small. Large units of distributed services will yield unpredictably complex tests, as those services scale their resource utilization over time.

Use the open source xUnit testing frameworks or vcr recording code functionality to conduct these unit test on microservices.

Integration testing

Integration tests can be used to validate how units function when they work together with the other units, and dependencies. Often, multiple microservices interact and execute together to achieve a business goal. Testers must monitor requests that flow through the services to ensure that communication channels function as expected.

Consider using an automated testing suite like Katalon Studio or open source Selenium to handle these integration tests.

Component testing

Component tests are used to test the components or services of an application in isolation. Although the component test zeros in on the microservice specifically, you should be able to mock the other services.

Component tests check microservices in isolation by creating mock services that mirror the deployed service. Component tests validate the interaction between a distributed service and its dependencies, such as the database and third-party components.

Hoverfly and other API simulators can help you with these component test processes -- look for tools that do stubbing and mocking

Contract testing

Contract testing is different than the functionality checks done so far. It verifies whether services communicating with any external third-party software components satisfy necessary legal requirements. To pass the test, the calls and responses must produce the same results every time, even if the service is altered or upgraded.

A contract test is particularly important when you have many distributed services running components of apps in production. To do contract testing on microservices, it is vital that both the service producer and consumer have the most up-to-date version of the contract.

Pact is a popular tool for contract tests and can help make it easier to validate these software agreements.

Next Steps

6 ways to perform microservices load testing

Dig Deeper on Enterprise architecture management

Software Quality
Cloud Computing
TheServerSide.com
Close