Testing microservices with Helios

Written by


Subscribe to our Blog

Get the Latest News and Content

As engineering organizations transitioned from monolith to microservices architectures, they sought to make their development efforts more scalable and manageable. The microservices paradigm promised to increase development speed and improve quality, while cutting down on maintenance costs. However, in real life, there are inherent quality caveats when it comes to developing in microservices. One of the main issues is testing. Microservices are much more difficult and complex to test than monolith architectures. This is especially true when attempting to replicate traditional testing methods to microservices. Unlike a monolith, the microservices architecture is made up of separate services that communicate with each other. While they function in production as related units, they are developed as independent units in different teams.

So while service A depends on services B – E when in production, this is often not reflected in the testing environment. If a developer runs traditional test methods for component A, the testing environment will not always include the up-to-date versions of services B – E, but perhaps older or incomplete versions of them (i.e., a mock). Which means service A isn’t being accurately tested for real-life, production behavior, and changes that are made to it might cause an unexpected downstream behavior.

We believe that in order to minimize bugs in production and increase developer velocity and confidence, microservices testing has to evolve and become more reliable.

Finding a Modern Solution for Modern Architectures

Helios is a developer platform designed specifically for testing and troubleshooting microservices. By leveraging distributed tracing, Helios provides granular visibility into the entire microservices architecture and into each service. This data is then used by Helios to automate the creation of microservices tests and to provide insights into specific failures and bottlenecks.

By using Helios, developers can go back to relying on testing as an essential and trustworthy step for delivering production-ready code.

Microservices Testing with Helios – Step by Step

Let’s see how it works.

Take a look at a typical testing scenario. Say we’re building a financial system that allows people to transfer money to each other, like PayPal or Venmo. A typical architecture includes the following components:

  • API service – An HTTP server that behaves as the system gateway, exposing the system’s external APIs
  • Users service – An HTTP server that manages all users and their permissions
  • Accounts service – A Kafka consumer that manages all account transactions
  • Payments service – An HTTP server working with 3rd party payments APIs (e.g., Stripe)
  • ֿFinancial service – An HTTP server that handles exchange rates by fetching them from 3rd party financial APIs
  • Emails service – A Kafka consumer that sends emails on different events in the system

In our scenario, the API service exposes a “/deposit” endpoint, which receives the receiving user’s email, currency, and amount. Say we’re tasked with adding a test that verifies a new capability – whenever a successful API call to “/deposit” is made, the email service should send an email to the receiving user, stating that a transaction to his/her accounts has been made successfully.

Why Traditional Testing Methods Fail

While this is a typical scenario, it’s not that easy to test with traditional testing methods that were designed for different needs. Challenges include:

  • Validating the email service behavior – The email service is a Kafka consumer, which means there’s no synchronous indication of its success/failure. How can we tell if the test passed and if the behavior we’re trying to validate actually occurred?
  • Generating the correct API payload – With hundreds (if not thousands) of API endpoints, generating the right payload for the API we’d like to test is like finding a needle in a haystack.
  • A “/deposit” request cannot be made to a non-existent user – The scenario requires a setup, i.e an API request that creates the receiving user. This requires more tinkering in the architecture before we can run the test.
  • Identifier creation – The test requests must share the same identifiers: the email, user id, etc. These need to be added. Moreover, the user id is generated dynamically as part of the test, and therefore cannot be hard-coded. How can we ensure all identifiers are correctly added in the right places?

Automated Test Generation and Customization

Helios enables the automated creation of this testing scenario while skipping over the hurdles a developer would have to figure out manually when testing with legacy solutions.

Step 1: Create a “setup action” for creating a user

First, navigate the system’s API to find the user creation request

testing microservices with Helios

Click on “Add as setup action”, and customize it. Helios supports parameterizing any parameters of the HTTP request by using the {{$var_name}} syntax. In the image below, you can see that two variables are defined: hostname and userEmail. Their value is defined globally and can be easily replaced.

testing microservices with Helios

Step 2: Create your test

Create an E2E test from the “/deposit” endpoint:

testing microservices with Helios

Afterwards, add the “Create user” setup action to the “/deposit” E2E test by adding it in the left pane menu:

testing microservices with Helios

You can see that a “setup action” node was added to the graph. After clicking on it, the right pane menu contains the setup action’s config that we just created.

Step 3: Customize

Let’s click on the “/deposit” request edge and customize it – we need to apply the hostname and userEmail variables, to make sure they are correlated with the setup action:

Testing microservices with Helios

Step 4: Generate test code

We can now generate the test code and see that all the variables are correlated:

testing microservices with Helios

Step 5: Validate email service behavior

Remember that we wanted to validate that an email was indeed sent from the emails service? We simply need to select the SES operation in the graph and configure the validation accordingly. Notice that we’re using the userEmail variable here as well.

Testing microservices with Helios

During the test, Helios also collects all the payloads automatically and regenerates the same API calls, including parameterization.

Advanced Testing Capabilities – Dynamic Variables

For more advanced test customization needs, Helios also provides the ability to add dynamic variables, i.e., variables whose values are populated as part of the test execution.

Helios supports extracting parameters from a setup action and using it at a later stage of the test. A typical example would be using the user ID that returns as a response from the “Create user” setup action and using it to make a query on the user’s balance.

To use dynamic variables, simply go the the response of the setup action, select the “custom” validation and extract the variable:

Testing microservices with Helios

Then, you can use this variable anywhere you like; in the case below, as part of the URL that queries the user’s balance:

Testing microservices with Helios

Ready to get started with your own testing scenario? Automate your microservices tests for free with Helios.

Subscribe to our Blog

Get the Latest News and Content

About Helios

Helios is a developer platform that helps you increase dev velocity when building cloud-native applications. With Helios, dev teams can easily and quickly perform tasks such as getting a full view of their API inventory, reproducing failures, and automatically generating tests, from local to production environments. Helios accelerates R&D work, streamlining activities from troubleshooting and testing to design and collaboration.

The Author

Related Content

OpenTelemetry trace visualization
New video: How to visualize your traces - tools and new ideas
Learn to visualize your traces and investigate issues, reproduce scenarios and generate tests for your cloud-native applications with a new developer tool.
Read More
4 ways to reproduce issues in microservices
4 Ways to reproduce issues in microservices
How to effectively reproduce issues in microservices with Python, JavaScript, cURL, Postman, and Helios. Investigate issues without the hassle.
Read More
Asset 27@4x-100
Testing microservices with Helios
Microservices architectures require a new type of testing. Here’s why traditional testing types fail and which new automated testing solutions can help.
Read More