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).
The integration tests will look at the application instance at
The example Java/Tomcat/Spring project
You can see the example project at https://github.com/codefreshdemo/cf-example-integration-tests. 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:
This pipeline does the following:
- Clones the source code with a Git clone step
- Builds a Docker image with only Tomcat and the application WAR
- Builds a helper image that contains the source code and Maven so that it can run integration tests.
- Runs the
mvn verifycommand 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.