How to Create Integration Tests Using GitHub Actions and Stellar's Docker Image
Last updated
Last updated
Testing helps detect errors before they reach production, improves software reliability, and provides confidence when making changes or adding new features. Among the various types of tests, integration tests are crucial for ensuring that an applicationโs modules work correctly together. In this article, weโll explore the benefits of integration testing and how to set it up locally and in a GitHub Actions pipeline using the stellar/quickstart Docker image.
Integration tests verify the interaction between multiple components of a system, such as databases, external APIs, and other services. The main benefits include:
- Error detection in module communication: Helps identify compatibility issues and logical errors.
- Risk reduction Ensures that code changes do not break existing functionality.
- Easier debugging Provides additional context when testing real-world scenarios.
Using the stellar/quickstart image allows you to set up a local environment to interact with the Horizon API and simulate Stellar operations. This eliminates the dependency on the production network, improving test speed and reliability. Below is a step-by-step guide.
This file defines the services needed to run the Stellar image. Add a Stellar service configured for a local network:
- image: Specifies the stellar/quickstart Docker image.
- command: --local: Configures the local network to run the tests.
- ports: Maps local port 8000 to the container for accessing the Horizon API.
With Docker Desktop installed, start the container by running:
This starts the service detached, and the Horizon API will be available at http://localhost:8000.
Next, we'll create a file named accountSetup.js to test basic operations:
These functions:
1. createFundedAccount: Creates a random account and funds it with 10,000 lumens using Friendbot.
2. getBalance: Retrieves the balance of an account using the Horizon API.
You can use a framework like Jest to write the tests:
Run the tests locally with:
The next step is automating the tests in GitHub Actions. This ensures that code changes are continuously validated.
Create a workflow file at .github/workflows/ci.yml:
This pipeline:
1. Configures a Docker service for Stellar.
2. Installs Node.js dependencies.
3. Runs the tests.
Performing integration tests using stellar/quickstart in Docker provides a controlled and reliable environment for validating functionality. Setting up a GitHub Actions pipeline improves efficiency by detecting errors before they reach production. These steps ensure that developers can focus on innovation while maintaining high code quality standards.
Resources: