HACKER Q&A
📣 simplotek

How do you test your microservices?


In previous discussions, I've noticed a few comments which complained that microservices were close to untestable, specially locally, and this was one of the main sources of negative sentiment towards this architectural choice.

However, these discussions tend to overrepresent developers experiencing problems than those who don't experience any significant problem at all as they managed to get things working. Therefore it would be helpful to hear from success stories and benefit from experience.

With this in mind, what'l strategies do you have in place to test microservices? What techniques do you use, what technologies do you have in place, and how do you structure your deployments?


  👤 twunde Accepted Answer ✓
The issue with microservices is that you typically can't run all the microservices at once on your laptop, making end to end tests more difficult. That said, the main benefit of microservices is that they enable independent teams. To that end, teams should be writing unit tests for the individual services. For any other services they interact with there should be common mocks for those services. These mocks are the service contacts for upstream/downstream services and should be tested in integration tests. Services go through the CI pipeline and are deployed independently. There is then an increased focus on monitoring especially on error rate

👤 simplotek
In a service I manage I have distributed tracing in place, as well as centralized logging.

I also have sandbox deployments in place that individual developers can take over and deploy the services they're working on to be able to test them in an environment that is very similar to the prod environment.

I also have in place a few Docker compose scripts for specific services that deploy a combination of dependencies, either the service itself or stubbed services.

For function-as-a-service code, I have special local-only, pre-beta deployment stages that fake clients.


👤 dragonwriter
Microservices are easily testable locally. An entire system composed of microservices may not be, but that’s what test environments are for.

What is the problem with testing microservices?


👤 BlueTie
Locally: Contract test (mock provider/consumer)

As part of CI/CD: Depending on complexity - basic functional tests against the specific endpoint or end-to-end test of API functions (using mocks when APIs aren't available).

Once deployed to pre-prod: Monitor just like prod - end-to-end functional tests w/routing rules to mocks when a certain microservices is unavailable.

Prod: Monitor using end-to-end functional tests.


👤 comprev
I've worked in places where Pact [0] was used for testing services developed by different teams (external) and teams themselves (internal)

[0] https://pact.io/


👤 Sevii
Unit tests, mocked integration tests and local end to end tests which make calls to the development environment.

Its not easy and there is no free lunch.