Unit Test with Database
Sometimes running unit tests requires some additional services like a Database (Mongo, MySql, Postgres etc), or third-party components like Redis, Memcache, etc.
Codefresh provides you an easy way to do it by using the 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 "Attach to Composition"
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 this. Just copy and paste this script to section of Unit Test Script
- Go to composition module and create a new composition just press (“+”), the wizard will propose you a few options. The most useful options is to create a new one or add
docker-compose.ymlfrom your repository. For this example just copy paste the following
- Put in the relevant composition component, for example,
mysqland save with 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.
- Save and Build this pipeline