Skip to content
Latchkey

mvn surefire:test: Usage & Common CI Errors

The goal behind mvn test - and where forked-JVM crashes are configured.

surefire:test is the goal of the maven-surefire-plugin that executes unit tests; it is what the test lifecycle phase binds to. Invoking it directly lets you tune forking and parallelism without re-running earlier phases.

What it does

surefire:test runs the compiled test classes, by default in a single forked JVM. forkCount and reuseForks control isolation/parallelism, and argLine sets JVM args (heap, agents) for the forked test JVMs.

Common usage

Terminal
mvn surefire:test
mvn test -DforkCount=1 -DreuseForks=false        # isolate each test class
mvn test -DargLine=-Xmx1g                          # heap for test JVM
mvn test -Dparallel=classes -DthreadCount=4

Common error in CI (and the fix)

Symptom: "The forked VM terminated without properly saying goodbye. VM crash or System.exit called?" Cause: the forked test JVM was killed (often an OOM kill / exit 137 on a memory-limited runner) or a test called System.exit. Fix: raise the test JVM heap with -DargLine=-Xmx1g and give the runner more memory, set forkCount=1 to reduce concurrent JVMs, and remove any System.exit in tests.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →