Running Tests against Containers

(Rob Winch) #1

I’m looking for the easiest way to run tests against some sort of container with Gradle. For example, I work with Spring Session which requires Redis, Cassandra, etc. I also work with Spring LDAP which requires various LDAP servers.

My thoughts are using something like gradle-vagrant-plugin or gradle-docker-plugin. I’m wondering what others recommendations are based on:

  • Ideally it would require no additional setup for someone to run the tests. Have JDK installed, clone the project, run the gradle wrapper and everything works.
  • If it does require additional setup, the simplest setup is desired
  • Up to date and maintained are also very important to me
  • I’d need to ensure the ports can be dynamic on a CI server and static if I wanted to run them from my IDE (I’m guessing this would be trivial)


(Benjamin Muschko) #2

Here’s the insight scoop of the person that implemented both plugins you mention above. :wink:

Using Vagrant

The plugin can start and stop a Vagrant box for you. You’d just have to point it to the Vagrantfile which contains the instructions. The downside is that you’ll have to ensure that Vagrant and some provider e.g. VirtualBox is installed on the machine running the build. That of course holds true for your CI machine as well. With Vagrant you can really install anything you want in the box you need for testing. For example this build script runs a Docker registry in a Vagrant box for testing purposes. A word of warning: Vagrant is horribly slow to start.

Using Docker

With Docker the story is slightly different. You can run Docker on a different machine and manage it with the remote API. That’s exactly what the Gradle Docker plugin does. It just calls off to Docker running on a different machine. Obviously that has benefits: you don’t need to install anything on the machine running the build. Before running your test you can simply start a Docker container with the setup you want to test and then tear it down after the fact. Also Docker containers are super fast to start. Constraint: You’ll have to set up Docker on a dedicated machine, create the images you need and add them to a Docker registry.

Other options

What you are basically looking for is a way to automatically provision infrastructure. There are some Gradle plugins out there that allow you to do exactly that e.g. provisioning-gradle-plugin. Downside is that they probably install the infrastructure on the machine running the build. That’s sub-optimal as it will persist and cannot be torn down after testing (except if you want to automate de-installing things that as well).

(Rob Winch) #3

Thanks for the response!

This is very useful information. I’m not sure where I have landed yet as I am also exploring things like

Thanks again :slight_smile:

(Predrag Knezevic) #4

You can run fully transparently any JUnit test inside a given Docker container using . I am the author and we use it a lot in my current company to speedup our testing rounds because you can run them in parallel, and in a full isolation. We even spread their execution in a Docker cluster, utilizing many machines at once.

Let me know if you need any help,