Sitemap

Dockerizing functional tests

2 min readMay 11, 2018

--

Functional testing is an important part of feature validation which makes sure your API/service works with real data end-to-end as opposed to jUnit testing which just validates a chunk of the code individually. One of the challenging part of functional tests is that you need to have a production like environment for your testing and you would not want to disrupt either your production or Pre-production environment. You could use a testing environment say a sandbox.However, there is a possibility of unexpected test failures due to any residual records which could be left out when you abruptly end your build or when there are any parallel execution of tests on your sandbox.

How About using a Virtual Environment?

We could use a virtual environment and set up the environment by installing the necessary software's similar to the local environment and run the functional tests in an isolated environment.However, you need to have the hardware for it, spin off the operating system and then set up the environment. Docker on the other hand is a container which just like any software that you install on any machine. You could spin many docker containers in the same machine parallely and all of them run as a separate environment that you could run your functional tests completely isolated and still testing on real data.

How to dockerize functional tests?

Get Keerthi Korvi’s stories in your inbox

Join Medium for free to get updates from this writer.

Lets assume that we have a Java API where we retrieve person details like his name,age, address etc from a MySQL database. Assume that you would retrieve your data from Person and Address table.

We first spin off a docker instance using the ‘docker’ executable and since we use a MySQL database we need to create an image of the MySQL database. Since this is an empty database we create utilities which are used to create tables and insert test data into the tables using these utilities.

Now point your connection url to the docker instance and voila you can run your functional tests in an isolated environment

Run a docker container as part of the maven build process

You could run a docker container and create images using a maven plugin called docker-maven-plugin where you specify the image name and the port on which it has to run. This automates the docker set up processes and before you run your tests make sure you have the necessary test data and then run your functional tests

--

--