Run integration tests
Launch separate App and test containers
In this example, we will see a Java/Tomcat project 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 (without mocking).
The integration tests will look at the application instance at app:8080
.
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:
codefresh.yml
This pipeline does the following:
- Clones the source code through a Git clone step.
- Builds a Docker image with only Tomcat and the application WAR through a build step.
- Builds a helper image that contains the source code and Maven to run integration tests.
- 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 to verify that the application
is actually up, before running the tests.
Related articles
CI pipeline examples
Integration tests with Postgres
Integration tests with MySQL
Integration tests with Mongo
Integration tests with Redis