Why does heap space run out only when running JUnit tests?

smauel picture smauel · Mar 25, 2009 · Viewed 44.1k times · Source

When running JUnit tests, I always seem to run into this error:

eclipse outOfMemoryError: heap space

I have monitored Eclipse with JConsole and heap memory peaks at about 150MB. I have set heap memory to 1GB.

I am using the following arguments when starting Eclipse:

-vm "C:\Program Files\Java\jre1.5.0_08\bin\javaw.exe" -vmargs -Xmx1024M
-XX:MaxPermSize=128M -Dcom.sun.management.jmxremote.port=8999
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false

Does anyone know what may be causing this issue? It happens only when running JUnit tests.

Answer

Thijs Wouters picture Thijs Wouters · Mar 25, 2009

Junit tests are run in a different vm as the Eclipse IDE. So it is that vm that is out of memory and not the Eclipse one.
You can change the settings of the test vm in the run configurations of the test.
You go to the run configurations and then under arguments, you can set the vm arguments.