It is possible to create a docker container which contains all needed test classes. Instead of executing the regular $JAVA_HOME/bin/java executable, a bash script will be invoked which creates a test image and executes the JVM within that image.

I just copied my JDK 1.8 folder and replaced the regular java binary with the bash script below. In Eclipse I only had to add this modified JDK folder and invoke the test using that JDK. This way the bash script below was executed by my Eclipse IDE. Next I needed to prepare the base image. The base image needs to contain the JDK. In my case I used the the registry.office/docker-jenkins-slave:latest image which is an internal Jenkins slave docker image which we use to execute our Jenkins jobs.

The bash script will split up the classpath and copy all needed files and folders to the BUILDDIR folder. After that a docker build will be invoked which create a docker image that contains all those files and folders. Then docker run will be used to execute the JVM within the image. It is important to note that your system hostname needs to be specified. The JVM process within the docker image will connect to your IDE in order to visualize the JUnit test results. Finally the build docker image is no longer needed and can be purged from the docker host.

Please keep in mind that the bash script and process will most likely not work on Windows, but it should be possible to transform the Windows classpath to a classpath which Linux understands.

Of course there are also some drawbacks to this solution:

The docker container must be able to connect to your host machine in order to communicate with the Eclipse IDE.

Multiple developers would also require multiple host machines. Executing two tests on one machine may already be enough to cause some deviations in the test performance and thus trigger some assertions.

Updates to the host operating system or even a hardware replacement may also cause test deviations.