Integration Testing
What
In Integration Testing
we test how all the components work together, means unlike unit tests we don't have to mock out the services. We actually start all the services in the integration test and see how they work together.
Downside to this is that it is slower, as we have to start all the auxiliary services.
Here is a gist of what we have to do in the Integration Testing
How
To do the integration test we will use scripts and docker compose file.
-
docker-compose.yml file
- It will start all the services -
script file
- It will run docker compose file, wait for our DB , migrate the DB , Do the Intial Seeding and run all the tests.
run-integration.sh
docker-compose up -d
echo 'π‘ - Waiting for database to be ready...'
# The below command will wait for the DB after that all the command run.
./wait-for-it.sh "postgresql://postgres:mysecretpassword@localhost:5432/postgres" -- echo 'π’ - Database is ready!'
npx prisma migrate dev --name init
npm run test
docker-compose down
# To run this file simply do `run-integration.sh` + you need to install wait-for-it.sh from github.
# curl https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -o scripts/wait-for-it.sh
For All the Steps Visit - 100xdevs Integration Testing
Thanks
Top comments (0)