2

I'm running junit tests from an ant script. The tests run successfully so ant moves on to the the junitreport task to create the html report. This task is failing with a java.lang.OutOfMemoryError: Java heap space error.

How can I increase the heap size for this task? Or is there another way to resolve this error?

Some additional information:

It was working fine until I added 40 additional tests

I've had a look at the xml output of the tests and it looks reasonable i.e. it's not full of long error messages.

Pulak Agrawal
  • 2,481
  • 4
  • 25
  • 49
macleojw
  • 4,113
  • 10
  • 43
  • 63
  • 1
    Try removing the frames if you can. It takes up lot of memory. You can also increase the heap space of ant in ant.bat or ant – vinothkr Nov 15 '10 at 08:56

4 Answers4

3

you can use the ANT_OPTS environment variable to increase the heap size ant uses

Nikolaus Gradwohl
  • 19,708
  • 3
  • 45
  • 61
2

This error has been raised in ANT bug 34342. The general consensus is that it's caused by excessive memory consumption in the XSLT used to generate the report, and it WON'T be fixed in ANT.

What has worked for me has been to increase the maximum heap size passed to ant, eg -Xmx3304m. As some of the other answers here mentioned, you can use ANT_OPTS to pass the maximum heap size to ant.

Regarding the actual maximum heap size value, it is recommended that it should be either 1/4th of physical memory or 1GB, whichever is smaller. You may need to go beyond the 1GB limit to avoid this memory error however. See Garbage Collector Ergonomics guide on the Oracle website.

Ivo Bosticky
  • 6,338
  • 6
  • 34
  • 35
0

You can use the maxmemory set within junit task itself.

<junit printsummary="yes" fork="true" haltonfailure="no" showoutput="yes" maxmemory="512m">

As the docs explain,

Maximum amount of memory to allocate to the forked VM. Ignored if fork is disabled. Note: If you get java.lang.OutOfMemoryError: Java heap space in some of your tests then you need to raise the size like maxmemory="128m"

JoseK
  • 31,141
  • 14
  • 104
  • 131
  • Actually that parameter change affects only the memory usage of the junit task, but unfortunately has no effect on the junitreport. @Nikolaus answer is a better approach. For example ANT_OPTS=-Xmx512m – Zsolt Mar 10 '11 at 14:10
0

The "maxmemory="###m" appears to ONLY work if you use fork, If you aren't using fork (like I am) it doesn't get used, You have to use the ANT_OPTS to change the heap.

Mark Hall
  • 53,938
  • 9
  • 94
  • 111
Sir Geek
  • 51
  • 3