Integration tests with Redis

Launching a Redis service container

In this example, we will see a Python project that is using Redis for storing a web counter. For the integration test phase we will launch both the application and an instance of Redis in order to run a simple integration test.

Redis integration tests with Codefresh

Redis integration tests with Codefresh

The application will be launched with a hostname web while Redis will be at redis:6379.

Example Python project

You can see the example project at The repository contains the Python source code and a test script.

You can play with it locally by using Docker compose to launch both the application and the Redis datastore.

Create a pipeline with Redis integration tests

Here is the whole pipeline:


version: "1.0"
  - prepare
  - build
  - test
    type: "git-clone"
    description: "Cloning main repository..."
    repo: "codefreshdemo/example_python_redis"
    revision: "master"
    git: github
    stage: prepare
    title: "Building Docker Image"
    type: "build"
    image_name: "python-redis-app"
    tag: "latest"
    dockerfile: "Dockerfile"
    stage: build
    title: "Building Docker Test Image"
    type: "build"
    image_name: "python-redis-app-tests"
    tag: "latest"
    dockerfile: "Dockerfile.test"
    stage: test
    title: "Running integration tests"
    stage: test
    image: '${{build_test_image}}'
      # Redis and app are certainly up at this point
      - sh ./
          image: redis:latest
            - 6379
          image: '${{build_app_image}}'
            - 80
        timeoutSeconds: 30
        periodSeconds: 15
        image: '${{build_test_image}}'
          - "nslookup redis"
          - "nslookup web"
          - "nc -z redis 6379"
          - "nc -z web 80"

This pipeline does the following:

  1. Clones the source code through a Git clone step.
  2. Builds a Docker image with the application itself through a build step.
  3. Builds a helper image that contains nc and curl that will be used for the integration tests.
  4. Runs the test script while launching two service containers (one for the app and one for Redis).

Notice that we also use the readiness property in the testing phase so that we can verify that both the application as well as Redis are up, before running the tests.

Integration test script

The integration test is very simple. It just uses curl to hit the Python endpoint and grep to check for a well known string.


if curl web | grep -q '<b>Visits:</b> '; then
  echo "Tests passed!"
  exit 0
  echo "Tests failed!"
  exit 1

Notice that we use the helper image both for running the test (because of curl) and for testing the readiness (because of nc). In a more complex application these could be two completely different images.

CI pipeline examples
Integration test example
Integration tests with Postgres
Integration tests with MySQL
Integration tests with Mongo