DEV Community

Cover image for Jump into Microservices Testing with Docker Compose and Skyramp
Dan Gross
Dan Gross

Posted on

Jump into Microservices Testing with Docker Compose and Skyramp

Distributed applications leveraging microservices have become a predominant approach for building scalable and maintainable software systems. As developers embrace the microservices paradigm, the need for effective testing solutions becomes increasingly vital. Skyramp, a powerful testing tool designed specifically for distributed systems, offers a robust solution to automate the testing of applications built on microservices.

My previous blog posts have focused on the array of options Skyramp provides for testing distributed applications deployed to Kubernetes clusters. However, Kubernetes is not required to reap the benefits of using Skyramp for test automation. You can also setup and deploy your system-under-test using Docker Compose. In this article, we'll explore how you can leverage Skyramp in conjunction with Docker Compose to streamline your microservices testing process.

For a quick overview on all the points this article will cover, you can check out this short video, "Skyramp & GitHub Codespaces with Docker," as a reference:

A Fly-By of Skyramp and Docker Compose

Before diving into the details, let's briefly introduce Skyramp and Docker Compose.

Skyramp: A Testing Powerhouse for Microservices

Skyramp is a testing tool specifically tailored for distributed systems built on microservices architecture. It provides a comprehensive set of features for automating the testing of various components within a microservices ecosystem. This includes: test generation, functional integration and performance testing, mocking services, hot code reload, and an integrated dashboard. While previous posts have centered around Kubernetes integration, it's important to note that Skyramp is versatile and can be employed with Docker Compose in place of Kubernetes.

Below is an architecture diagram showing where the Skyramp components fit in a Docker Compose setup for conducting automated testing:

Image description

Docker Compose: Simplifying Orchestration

Docker Compose is a tool for defining and running multi-container Docker applications. It allows developers to define a multi-container environment in a single file, making it easy to set up and manage complex microservices architectures. Docker Compose is an excellent choice for local development and testing, providing a lightweight alternative to full-scale orchestration solutions.

Setting the Stage

To set some context before jumping into the walkthrough, let's first look at a few key concepts:

Example Repo from Skyramp

Skyramp provides a sample project, sample-microservices, which serves as an excellent starting point for demonstrating testing and mocking with a full-featured distributed application. The application is based on Google's Online Boutique repo, which is an e-commerce store consisting of 11 different microservices. The docker-compose-demo branch referenced above showcases how Skyramp can be seamlessly integrated with Docker Compose for testing microservices with no local setup required. You can also clone the repository and explore the structure of the microservices setup for your own purposes.

Mocks for Simulating Dependencies

One powerful aspect of Skyramp is its ability to handle dependencies and external services through mocks. Define mocked services with a mock description for Skyramp's Mocker to simulate the behavior of external dependencies. This allows you to isolate and test individual microservices in a controlled environment.

Dashboard for Test Results

Skyramp includes a dashboard for organization and analysis of your test results. Integrate the Skyramp dashboard into your testing setup to gain insights into tests, performance metrics, and potential issues. The dashboard enhances visibility, making it easier to identify and address issues in your microservices deployment. To spin up the dashboard for Docker locally with the CLI, simply run skyramp dashboard up --docker from your terminal.

Docker-Specific Docs

Because Docker Compose is markedly different than Kubernetes in terms of setup and certain behaviors, the Skyramp docs have been tailored to provide Docker-specific instructions. There you can discover the many ways Skyramp can help you with your testing strategy for Docker Compose deployments.

A Simple Walkthrough

As mentioned above, we will use the Online Boutique distributed application for our example system-under-test. We can easily create a running test environment using GitHub Codespaces. To launch your own environment so that you may follow along, simply click the link below and then click "Create codespace."

Open in GitHub Codespaces

Bringing Up Services

Once the Codespace launches, you will see a VSCode window in your browser. The repo source files are pre-loaded and a terminal pane is available. In the root folder of the repo, you will see a shell script called workflow-1.sh. Executing this script will bring up the system-under-test using a pre-configured docker-compose.yml file under the skyramp/docker-compose folder. Go ahead and give it a spin from the command line:

sh workflow-1.sh &
Enter fullscreen mode Exit fullscreen mode

At this point you should see a screen similar to this one, which shows the output from the running docker containers:

Image description

The system-under-test deployment is comprised of the services we need to conduct a test of the checkout process, namely the product catalog, cart, payment, and checkout services.

Our pre-defined test scenario in this case will aim to test the checkout flow. First, change directories in the terminal:

cd skyramp/docker-compose
Enter fullscreen mode Exit fullscreen mode

Next, let's go ahead and run our test. The test itself is defined under tests as checkout-test.yml, which you can review in the VSCode window from the codespace or by navigating here. To run, execute:

skyramp tester start checkout-test --address localhost:35142
Enter fullscreen mode Exit fullscreen mode

Uh-oh, it looks like the test failed because the checkout process could not connect to the payment service.

Image description

Truth be told, we did that on purpose. This allows us to demonstrate how we can bring up a mock of the payment service using Skyramp Mocker. Simply run:

skyramp mocker apply --address localhost:35142
Enter fullscreen mode Exit fullscreen mode

The mock is defined under mocks as payment-service-k8s.yaml, which you can review in the VSCode window from the codespace or by navigating here.

With the payment service mock in place, let's re-run our checkout test:

skyramp tester start checkout-test --address localhost:35142
Enter fullscreen mode Exit fullscreen mode

Here we see the test scenario passes, so we have successfully tested our checkout components in concert to validate that the microservices are behaving as expected in the flow. Great work, give yourself a pat on the back.

Image description

Wrapping Up

Incorporating Skyramp with Docker Compose offers a seamless and efficient approach to testing microservices locally. By leveraging Docker Compose's simplicity for setting up multi-container environments and Skyramp's comprehensive testing capabilities, developers can ensure the reliability and performance of their microservices architectures. Whether you're new to microservices testing or looking to enhance your existing workflows, the combination of Skyramp and Docker Compose provides a powerful solution for robust and automated testing. As always, happy testing.

Finally, please join our Discord for any questions, comments, or feedback.

Top comments (0)