Mockito, jacoco and surefire causes out of memory
Asked Answered
S

2

5

I am using mockito 1.8.3, jacoco 0.72 and maven 3.0.5 surefire plugin (2.12.4) to execute unit test and generating coverage report, it was working fine.

With more and more tests are added, it starts not working. I continuously encounter out of memory error during test execution, and cannot find out a way to figure out what is wrong.

I have about 1800+ test cases with mockito as the mocking tool. It is working fine if I do not run jacoco during maven test with "org.jacoco:jacoco-maven-plugin:prepare-agent " before test phase, but as long as I add jacoco agent, I get OOO issue with PermGen full.

I already added the PermGen to 2GB by modifying MAVEN_OPTS (which should not work since surefire will fork a new process) and surefire argline argument in pom, but it does not help a lot.

I try to get a core dump when OOO occurs by adding parameter to surefire plugin, but never saw a dump file in any folder. I am suspicious that my JVM setting does not work for the surefire plugin, but not sure what is wrong. Anyone could do me a favor? Thanks.

            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${surefire.version}</version>
                <inherited>true</inherited>
                <configuration>
                    <properties>
                        <property>
                            <name>argLine</name>                                    <value>-server -ea -XX:-UseSplitVerifier -XX:MaxPermSize=2g -Xmx3g -XX:+HeapDumpOnOutOfMemoryError </value>
                        </property>
                        <property>
                            <name>forkMode</name>
                            <value>once</value>
                        </property>
                        <property>
                            <name>reportFormat</name>
                            <value>plain</value>
                        </property>
                        <property>
                            <name>skipTests</name>
                            <value>${maven.test.skip}</value>
                        </property>
                    </properties>
                </configuration>
            </plugin>
Squirrel answered 2/3, 2015 at 10:7 Comment(1)
Still having issue, any help please ?Sheng
C
6

You need to set the memory for maven-surefire-plugin like the following:

<plugins>
[...]
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <configuration>
        <forkCount>3</forkCount>
        <reuseForks>true</reuseForks>
        <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
        <systemPropertyVariables>
            <databaseSchema>MY_TEST_SCHEMA_${surefire.forkNumber}</databaseSchema>
        </systemPropertyVariables>
    </configuration>
  </plugin>
[...]
</plugins>
Creon answered 2/3, 2015 at 10:15 Comment(2)
Thanks, it is working. Not sure why the "property" format I use does not work.Squirrel
I'm facing still issue, can you please help me ?Sheng
K
2

In case you have jacoco configured along with maven failsafe plugin, then you will need to pass memory parameters to that one too:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-failsafe-plugin</artifactId>
   <version>2.14.1</version>
   <configuration>
      <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
   </configuration>
</plugin>
Kame answered 23/9, 2015 at 11:18 Comment(1)
Vadim, still having issue, can you please help me ?Sheng

© 2022 - 2024 — McMap. All rights reserved.