Wednesday, May 02, 2007

OutOfMemory issue in JUnit

Recently one of my colleague encountered this issue when running a JUnit test. Inspite of increasing the -vm settings the error kept coming. On further research we found that if JUnit is set with "fork=true" the task will be executed in forked VM. So the memory settings of default VM will not effective. So, you need to set maxmemory attribute of JUnit to avoid OutOfMemory? exception.

Example:

<target name="test.class.inner" if="test.class">
      <echo message="test.classpath"/>
      <mkdir dir="${test.output.dir}"/>
      <mkdir dir="${build.dir}/tmp"/>
      <junit dir="${build.dir}" haltonfailure="yes" haltonerror="yes" printsummary="on"
            fork="true" filtertrace="true" '''maxmemory="1024m"'''>
      <sysproperty key="merchantize.env" value="test"/>
....

No comments:

Post a Comment