Build and run all junit tests in parallel with each test class in its own JVM (parallelization by classes, not by method)

Problem
I have a bunch of junit tests (many of them with custom runners like PowerMockRunner or JUnitParamsRunner) under some root package tests(they are in different subpackages testsat different depths).

I would like to collect all the tests in the package testsand run each test class in a different JVM in parallel. Ideally, parallelization will be configurable, but the default value of number_of_cores is also fine. Note that I do not want to run each method in my own JVM, but each class.

Background
I use PowerMock in conjunction with JUnitParams through annotations @RunWith(PowerMockRunner.class)and @PowerMockRunnerDelegate(JUnitParamsRunner.class)for many of my tests. I have 9000 unit tests that end in a “normal” amount of time, but I have an 8-core processor, and the systems are heavily underused by default for a single time test. Since I run tests quite often, extra time is added, and I really want to run test classes in parallel.

Please note that, unfortunately, in a large number of tests I need to mock static methods, which are part of the reason I use PowerMock.

What I tried
To mock static methods, it is impossible to use something like com.googlecode.junittoolbox.ParallelSuite(this was my initial decision), since it runs everything in one JVM, and static mockery is all interleaved and mixed up. Or so it seems to me, at least based on the errors that I get.

I don’t know the JUnit stack at all, but after it popped out, it seems that another option might be to try to write and enter your own RunnerBuilder, but I'm not sure if I can even create another JVM process from the inside RunnerBuilder, hardly. I believe that some kind of harness that works as a gradle task would be the right solution.

JUST Android Studio (Intellij's), fork method, , . , , , , , , .

UPDATE. , Android Studio (Intellij), Test Kind: All in directory ( - ) Class. , - , , , . , , ...: (

+2
2

. , , .

JUnit Intellij (Android Studio) , Android Studio gradle, . , . gradle root build.gradle:

subprojects {
    tasks.withType(Test) {
        maxParallelForks = Runtime.runtime.availableProcessors()
    }
}

, 100% ( , < avail , , ).

, Android Studio (Intellij) . , gradle , .. , HTML. , , , , JUnit runner.

+2

, , , Android.

gradle: 'com.android.tools.build:gradle:2.2.3'

build.gradle.

allprojects {
    // ...
    tasks.withType(Test) {
        maxParallelForks = Runtime.runtime.availableProcessors()
    }
}

Gradle Test Executor . , !

, !

+1

All Articles