If you have memory allocation errors related to the "permGen" space, it means you run with a Java 7 or inferior. So, as a side note, if you run a Java 8 or superior, you shouldn't see this error anymore since that space doesn't exist per se anymore and is only limited to the available native memory.
The JVM option to manage the PermGen space is XX:MaxPermSize
. So you should add to the JVM with runs your unit tests this command line argument: -XX:MaxPermSize=256m
.
The ANT_OPTS
environement variable will configure the JVM used by Ant itself. You should use this environement variable if the unit tests are not ran as forked.
If you run your unit tests in a JVM forked by Ant, then you should tell Ant to start the Junit task with some additionnal JVM arguments. The parameter you need to use is jvmarg
.
See the official Ant documentation about the task: https://ant.apache.org/manual/Tasks/junit.html
Thus, here is the piece of XML to set the proper property:
<junit fork="yes">
<jvmarg value="-XX:MaxPermSize=256m" />
</junit>