Executing JUnit Tests belonging to a class in Parallel?


(Pani Kumar) #1

I have 3 test classes (TestClass1, TestClass2 and TestClass3). TestClass1 has 3 tests. TestClass2 has 3 tests. TestClass3 has 20 tests.

Here is the task which runs tests.

task regressionTests(type: Test, description: ‘Runs regression tests in parallel’) {

useJUnit {

includeCategories ‘org.junit.categories.ParallelTest’

}

maxParallelForks = 10 }

What I could see is that 3 threads spawned (though maxParallelForks = 10) and 3 threads picked one test class each. Within each thread, the tests are getting executed sequentially.

What I would like is execute 10 tests in parallel.


(Peter Niederwieser) #2

To explain the behavior that you are seeing, Gradle can execute test classes in parallel (not just in different threads but in different JVMs), but all test methods in the same class get executed sequentially.


(Pani Kumar) #3

Yes Peter. That is exactly what is happening. Thanks for rephrasing :slight_smile: Just wondering if there is a way to execute test methods also in parallel (which belong to a same class) ?


(Peter Niederwieser) #4

No, there isn’t. (That’s what I was trying to say.)


(Pani Kumar) #5

Ok. Thanks Peter.