# \[ANN\] Plugin for running test within a Docker container

**URL:** <https://discuss.gradle.org/t/ann-plugin-for-running-test-within-a-docker-container/620>\
**Category:** Old Forum Archive\
**Created:** [February 4, 2015, 8:18pm UTC](https://discuss.gradle.org/t/ann-plugin-for-running-test-within-a-docker-container/620 "2015-02-04T20:18:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Predrag\_Knezevic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/predrag_knezevic/32/217_2.png) [@Predrag\_Knezevic](https://discuss.gradle.org/u/Predrag_Knezevic)\
**Post date:** [February 4, 2015, 8:18pm UTC](https://discuss.gradle.org/t/ann-plugin-for-running-test-within-a-docker-container/620/1 "2015-02-04T20:18:00Z")

</div>

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 ============

- [Docker](http://www.docker.com) \* this plugin

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](https://registry.hub.docker.com/u/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

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.

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [February 5, 2015, 10:18pm UTC](https://discuss.gradle.org/t/ann-plugin-for-running-test-within-a-docker-container/620/2 "2015-02-05T22:18:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Predrag\_Knezevic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/predrag_knezevic/32/217_2.png) [@Predrag\_Knezevic](https://discuss.gradle.org/u/Predrag_Knezevic)\
**Post date:** [February 5, 2015, 10:33pm UTC](https://discuss.gradle.org/t/ann-plugin-for-running-test-within-a-docker-container/620/3 "2015-02-05T22:33:00Z")

</div>

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

We at DataStax are using the plugin happily 🙂

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.

---

<div class="post-metadata">

**Author:** ![Nikem](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/nikem/32/232_2.png) [@Nikem](https://discuss.gradle.org/u/Nikem)\
**Post date:** [February 11, 2015, 12:06pm UTC](https://discuss.gradle.org/t/ann-plugin-for-running-test-within-a-docker-container/620/4 "2015-02-11T12:06:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Predrag\_Knezevic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/predrag_knezevic/32/217_2.png) [@Predrag\_Knezevic](https://discuss.gradle.org/u/Predrag_Knezevic)\
**Post date:** [February 18, 2015, 7:24pm UTC](https://discuss.gradle.org/t/ann-plugin-for-running-test-within-a-docker-container/620/5 "2015-02-18T19:24:00Z")

</div>

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
