Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit test runs out of memory -- how to increase heap size?

I am running a Junit test which throws an exception OutOfMemory. The test is started inside NetBeans 6.9.X. When profiling it I've realized that the Heap maxSize is 64M. I would like to increment this but I couldn't find how to do this.

I already tried right click at the project ->properties ->Run and under the VM options I've set -Xms300M but this didn't work.

Any hint?

Thanks in advance.

like image 520
Luixv Avatar asked Sep 15 '11 16:09

Luixv


People also ask

How do I fix out of memory error in Junit?

Junit tests are run in a different vm as the Ee IDE. So it is that vm that is out of memory and not the Ee 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.

How do I fix heap memory error?

How to fix it: In some cases, to mitigate the problem, it is enough to increase the maximum heap size by adding the -Xmx to your JVM application startup settings and setting it to a larger value.


2 Answers

From http://wiki.gephi.org/index.php/NetBeans_Tips#How_to_increase_Heap_Size_for_JUnit_test

Edit your project.properties file and add the line:

test.run.args=-Xms128m -Xmx1400m
like image 191
Roshan Avatar answered Nov 16 '22 01:11

Roshan


You can also increase the max size for all VMs by setting this environment variable for your OS:

 _JAVA_OPTIONS=-Xmx300m
like image 21
JRL Avatar answered Nov 15 '22 23:11

JRL