How to execute JUnit tests in parallel?


(pmendelski) #1

Hi,

I would like to run JUnit (Spring + Spock) tests in parallel without spawning JVMs.
Is it possible? How can I do it?

I am interested in same functionality as in maven-surefire-plugin


(pmendelski) #2

I found exact same question on Stackoverflow from 2015

Unfortunately it seems that this feature still does not exist.

Do you plan to add this feature in Gradle v3?


(Chris Beams) #3

Hi Pawel, it sounds like you’re aware of our support for parallel test execution documented at https://docs.gradle.org/3.0/userguide/userguide_single.html#sec:test_execution, but that you want to achieve parallel execution without forking. Is that correct? Could you say a bit about why forking isn’t an option or isn’t desirable in your case?


(pmendelski) #4

Hi,

Thanks for your prompt reply.

Yes, your understanding is correct. I want to achieve a parallel test execution without forking whole JVM. I would like to achieve it on a test level.

My problem with forking is that it simply takes too much time and resources.

Details:
At the moment I am working on a project that uses Spring Framework. As you know Spring context initialization is a time consuming task. It’s even worse if you take into account that integration tests use embedded MongoDb. With current approach every fork creates new Spring Context and starts a new embedded MongoDB instance. All of that takes simply too much time and resources.


(Chris Beams) #5

Are you using Spring’s TestContext Framework? Among other things, it is designed to allow you to reuse the same ApplicationContext across multiple test executions. This means that tests typically run much faster, and that as a result, you may not need parallel execution as much.


(pmendelski) #6

Yes, I am using TestContext Framework. Please don’t get me wrong my tests are not super slow right now. I just want to use whole computing power of a multicore machine to make tests run as fast as possible. It’s tempting to reduce test time by 50% just by parallel execution.


(pmendelski) #7

Is this topic closed? :slight_smile:

Are you planning to add such a feature to gradle?
If yes is there an issue to subscribe on?


(radistao) #8

Very-very nice to have. Any updates? Plans?


#9

Is there any alternative solution or plugin to use? I also want to use one JVM with multiple threads.

I want to implement a static counter for a whole test run and if i use Gradle with maxParallelForks there is separate counter in each fork. Can anyone help?


Running integration tests in parallel for each test class, with multiple sub-projects
(uklance) #10

Perhaps you could start a restful api running in jetty or an MBean before all the tests start a which you shut down after. The tests could then connect to the service