Skip to content
Latchkey

Gradle "Test framework quit unexpectedly" - Fix in CI

The forked JVM running your tests died before reporting results. On CI this is usually the OOM killer, a JVM crash, or a native library fault inside the test executor process.

What this error means

The test task fails with Process 'Gradle Test Executor N' finished with non-zero exit value or The forked test process quit unexpectedly, with no individual test failure - the executor itself vanished.

gradle output
> Task :app:test FAILED
> Process 'Gradle Test Executor 3' finished with non-zero exit value 137
  This problem might be caused by incorrect test process configuration.
  Please refer to the test execution section in the User Manual ...

Common causes

Test JVM OOM-killed

The forked test JVM, plus the daemon and other workers, exceeded the runner RAM and the kernel SIGKILLed the executor (exit 137). No catchable exception is produced.

JVM or native crash in a test

A System.exit() in test code, a JNI/native library fault, or an incompatible agent can hard-crash the executor process mid-run.

How to fix it

Bound the forked test JVM memory

Cap the test JVM heap and limit forks so the executor fits in the runner.

build.gradle.kts
tasks.test {
    maxHeapSize = "1g"
    maxParallelForks = 1
    forkEvery = 100
}

Diagnose a non-memory crash

  1. Re-run with --info and inspect the executor exit code; 137 indicates an OOM kill.
  2. Check for System.exit() in test code or a fatal-error log (hs_err_pid*.log) from a JVM crash.
  3. Disable suspect Java agents or native libraries to isolate the fault.

How to prevent it

  • Cap maxHeapSize and maxParallelForks for the test task, avoid System.exit() in tests, and size the runner to the test JVM footprint.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →