Integration Tests Example

Launching separate App and test containers

In this example we will see a Java/Tomcat project that is using JUnit for unit tests and Spock for integration tests. For the integration test phase we will launch both the application and the tests in order to run the integration tests against a real web instance (i.e. without mocking).

Integration tests with Codefresh

Integration tests with Codefresh

The integration tests will look at the application instance at app:8080.

The example Java/Tomcat/Spring project

You can see the example project at The repository contains the Java source code and some integration tests.

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

Create a pipeline with separate integration tests

Here is the whole pipeline:


version: "1.0"
  - prepare
  - build
  - test
    type: "git-clone"
    description: "Cloning main repository..."
    repo: "codefreshdemo/cf-example-integration-tests"
    revision: "master"
    git: github
    stage: prepare
    title: "Building Docker Image"
    type: "build"
    image_name: "my-spring-app"
    tag: "master"
    dockerfile: "Dockerfile"
    stage: build
    title: "Building Docker Test Image"
    type: "build"
    image_name: "my-junit-spock-tests"
    tag: "master"
    dockerfile: "Dockerfile.testing"
    stage: test
    title: "Running integration tests"
    stage: test
    image: '${{build_test_image}}'
      # Tomcat is certainly up at this point
      - mvn verify
          image: '${{build_app_image}}'
            - 8080
        timeoutSeconds: 30
        periodSeconds: 15
        image: byrnedo/alpine-curl
          - "curl http://app:8080/wizard/"

This pipeline does the following:

  1. Clones the source code with a Git clone step
  2. Builds a Docker image with only Tomcat and the application WAR
  3. Builds a helper image that contains the source code and Maven so that it can run integration tests.
  4. Runs the mvn verify command in the helper image while launching a service container with the Tomcat/Java image

Notice that we also use the readiness property in the testing phase so that we can verify that the application is actually up, before running the tests.