Updated 9/5/2020

In the previous versions of this article, I’ve stated that theseed container doesn’t have to wait for thedb container. That turned out not to be the case. The article has been corrected. If you prefer looking at code — here’s a sample repo that uses everything described below.

karpikpl/tests-with-docker-compose

Azure functions node-js project generated using yeoman Requirements: Nice to have: docker and docker-compose As with…

github.com

Integration tests are hard

I’ve been toying with the idea of doing integration tests with docker-compose for a while and that time has finally come :)

This guide should apply to any application that is stateful, with a data store that can be dockerized (not Cosmos DB).

I want a one-script solution — no manual steps. It needs to run both locally and on the continuous integration server (Azure DevOps in my case).

The tests that I want to add are calling a node.js azure function that talks with MS SQL server and returning data from the database.

Image for post

Docker compose file that we’re building

The Application

The application consists of two layers — azure function running node.js and MSSQL 2019 Server. There’s also some test data I want to push to the DB before tests are executed.

The issue

While adding docker-compose for an app is fairly easy, and there’s plenty of great guides and tutorials out there, docker-compose is not designed to be an orchestration tool for setting up the DB, then seeding it with data, starting the app, and executing tests. In production scenarios, applications should be resilient to any of its dependencies being not available, so integration testing is somewhat an edge case. We really just want the test to wait until everything is ready, execute, and give us the results.

Materials

Before I show you the solution — here are some great materials that I used to assemble this post.

Integration Testing With Docker Compose

Integration testing is often a difficult venture, especially when it comes to distributed systems. Even if you’re…

blog.harrison.dev

How can I wait for a container to exit? · Issue #5007 · docker/compose

I have a scenario where a container should only be “kept running” in development. In production, it just compile some…

github.com

#docker-compose #integration-testing #azure-functions #docker #nodejs

The Ultimate Guide to Integration Testing With Docker-Compose and SQL
7.00 GEEK