[ANN] Plugin for running test within a Docker container

What ====

Gradle plugin for running test within a Docker container.

Why ===

Running functional and integration tests in parallel on a single machine, testing complexer setups, and better test isolation.

Requirements ============

Usage =====

buildscript {

repositories {

jcenter()

}

dependencies {

classpath “com.pedjak.gradle.plugins:dockerized-test:0.3”

}

}

apply plugin: ‘com.github.pedjak.dockerized-test’

The plugin registers to each of test tasks ‘docker’ extension:

test {

docker {

// base image for creating docker containers that execute the tests

image = ‘foo/testimage’

// volumes mounted to the containers

// in a form: host_dir : container_dir

volumes = [ “/foo/bar”: “/foo/bar”]

// specify the user for starting Gradle test worker

// within the container, default to current user

user = ‘root’

argsInspect = { List args ->

// custom args processing and tweaking

// of the docker command starting the testworker inside a container

// returned args will be used for the final docker container start

args

}

}

}

  • ‘docker.image’ should point to a Docker image having a JDK installed. A good starting point is

dockerfile/java set of images and customize them to your needs if necessary. If the property is left empty, the tests will be executed using the standard Gradle mechanism.

  • ‘docker.volumes’ is prepopulated so that the docker container mounts:

  • the Gradle home, usually ‘$HOME/.gradle’

  • the project root

    • ‘docker.user’ is prepopulated with UID of the the current user.

If not appropriate, you can replace with an another UID.

  • finally, if all above options are not serving your needs, you can fully customize the invocation of the Gradle test worker inside a Docker container by registering a closure to ‘docker.argsInspect’. It is invoked before the container start, providing you access to all arguments of ‘docker’ command. The closure must return a list of arguments that is going to be used for the final docker container start.

This is some great work. Thanks for sharing and contributing.

I put something out on Twitter about this and it got a lot of attention.

Thanks, stay tuned for a few improvements I have in mind… like testing across a Docker cluster :slight_smile:

We at DataStax are using the plugin happily :slight_smile:

Predrag

p.s. it would good to think about refactoring a bit the code around DefaultWorkerProcessFactory and JavaExecHandleBuilder - right now you have to copy a lot of code from there (into some new classes) if you want to change just a bit of behavior.

Hello, Predrag.

How can I use this plugin for running integration tests that consists of multiple steps? E.g. I have a task named “selenide” which dependsOn task “startApp”, which starts my application. I want application to start inside Docker container before my selenide task. How can I achieve that?

Hi,

Sorry for a late response, lot of thing on my plate.

You can create a docker container containing your application, so that “startApp” starts the container, and they you use such container as basis for running your tests.

I hope it helps,

Predrag