How can I run one Junit test at a time?


(binarylegit) #1

I’m trying to fix our CI build of a specific project, this specific project has several JUnit tests that each individually load into memory about 1GB of data and then perform operations on it. The build server only has 4GB of memory and so when Gradle starts running tests and spins up multiple worker’s for them the workers are quickly killed because they are taking too much memory and they fail. My main question is this: how can I tell Gradle that I only want to run a single test at a time (meaning synchronous tests not asynchronous)?

I realize the real issue is that I need to fix the tests so that they don’t each require 1GB of memory, however I’ve spent a while trying to figure out how to tell Gradle to only run a single test at a time and have been unsuccessful so I am posting this question.

I’m using gradle 2.14 and I’ve tried the --max-workers=1 option which seems to have no effect and I’ve tried setting org.gradle.parallel=false which also doesn’t seem to have any effect. I’m assuming I’m either doing something wrong or just plain misunderstanding how to run only one test at a time. Any help is greatly appreciated.

(binarylegit) #2

The following added to the build file seems to have fixed the tests, now only one worker is created to run the tests:

tasks.withType(Test) {
maxHeapSize = "2048m"
maxParallelForks = 1
jvmArgs “-Xmx2048m”