Unit Tests with Composition
Sometimes running unit tests require some additional services such as a Database (Mongo, MySql, Postgres etc.) or third-party components like Redis, Memcache, etc.
Codefresh provides you an easy way to do this by using a Codefresh pipeline and docker-compose.
To run Unit Tests with a DB or other services you can create a composition and run your unit tests as part of it.
Fork this repository in GitHub to continue
How to do it using option "Replace Service"
Navigate to added example repository, select relevant pipeline and put in your test script in Unit Tests Section. For this example, your unit test script will be something like that. Just copy and paste this script to Unit Test Script section.
- Go to composition module and create a new composition just press (“+”), the wizard will propose a few options. The most useful is to create a new one or add
docker-compose.ymlfrom your repository.
- In your composition, put the relevant component. For example, mysql and save with a relevant name.
- Go to back to pipelines of this repository.
- Select the
Run tests with compositionoption and choose the created composition you wish to run your image in while running the Unit Tests.
- Choose the option
Replace Serviceand select which service in the composition will be replaced by the image built by this pipeline.
- Save and Build this pipeline.