I'm new to Docker and was reading up on Docker. It's a great way to test systems in a self contained and reproducible standardized configuration (when done correctly).
However, in all the things I've read, there doesn't seem to be too much emphasis on how the testing should occur with docker containers. The docker is used to "contain" the infrastructure and application (code) for easy testing (as well as deployment). But sometimes test codebases are be large and not so simple too. And one can have a test codebase for API tests, another for UI, etc.
What is or should be (as determined at some point) the standard practice for testing docker containers/deployments of your applications/infrastructure? Should:
The only reason I can think of that make dockerizing tests perhaps useful is that it's a single container with all the tests you need and the matching test infrastructure (all the test platform/language dependencies) so that one can deploy and run tests anywhere together with the matching app code containers. Saves one from having to set up test infrastructure when/as needed. But no seems to have blogged about such a thing for dockerized tests.
Dockers allow you to test in containers and isolate your tests for both development and deployment. Testing becomes predictable, which assures you that when something works on your system, it will also work for your end users.
At a high level, Docker makes it faster and easier to spin up services using a variety of configurations. This translates into a number of advantages when running your tests in Docker: You can keep server configuration in code. Any developer or CI environment will run the exact same setup.
Top advantages of Docker for testers Teams can repeatedly spin up a Docker container from an image and produce the same, unmodified application on every startup. This means Docker containers are reproducible, reusable and, therefore, well suited for destructive testing.
I prefer your option (3) i.e. to include test code in the production deployable artifact (the docker image)
Will quote Alister Scott from GTAC 2015 which I attended:
Don’t be afraid to add testability specific features to your app that don’t serve a functional purpose. I recently had to get new tyres on my car and realized that a lot of tyres have testability features called tread indicators. These don’t serve a functional purpose
For integration and e2e tests, i.e. tests that require more than 1 docker image to be used, I prefer CI tool that, through docker-compose, and a separate git repo for these tests, orchestrates the creation of all containers that are needed for the larger test. Again the docker images used should be the exact same as for production except what varies is the configuration (e.g. environment variables) that make the tests point to test data and/or staging services.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With