The accepted answer above works but the Gradle documentation here suggests you use
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
I tried both and after testing both on a 2.3 GHz Intel Core i7 Mac Book Pro with 16GB RAM (4 cores with hyperthreading)
test {
maxParallelForks = Runtime.runtime.availableProcessors()
}
and
test {
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
}
The approach suggested by Gradle documentation produced faster response times for our unit test suite: 7 minutes vs. 8 minutes (compared to the original 13 minutes). In addition my Mac CPU didn't get pegged and the fan didn't kick off.
I assume there is either contention on a shared resource - even if it is only the machine one which we are running the unit tests.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…