Showing posts with label JUnit. Show all posts
Showing posts with label JUnit. Show all posts

Tuesday, April 7, 2009

Bookmark and Share

When using the JUnit task for Apache Ant I recently came across the following error:

1
2
3
4
5
6
7
8
9
10
...
[junit] Error occurred during initialization of VM
[junit] Could not reserve enough space for object heap
[junit] Could not create the Java virtual machine.
[junit] java.io.FileNotFoundException: /home/.../junitvmwatcher995964737.properties (No such file or directory)
[junit]     at java.io.FileInputStream.open(Native Method)
[junit]     at java.io.FileInputStream.(FileInputStream.java:106)
[junit]     at java.io.FileReader.(FileReader.java:55)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeAsForked(JUnitTask.java:1028)
...

At first I was rather distracted by the FileNotFoundException, but then I recognized that the message "Could not reserve enough space for object heap" might be a pointer to the actual problem.

My build file contained a target for the execution of JUnit tests roughly looking as follows:

1
2
3
4
5
6
7
8
9
10
11
12
...
<target name="junit" depends="jar">
    <junit printsummary="true" fork="true" forkmode="perTest" maxmemory="2048m">

        <classpath>...</classpath>

        <batchtest>
            <fileset dir="${src.dir}" includes="*Test.java"/>
        </batchtest>
    </junit>
</target>
...

When I decreased the value for the maxmemory attribute the error went away. I thought a rather large value here wouldn't do any harm, as I expected that only the actually required amount of memory would be allocated.

But obviously the JUnit task tries to allocate the total amount of memory up-front, causing the test to fail on my system, which only has 2 GB of RAM altogether.