2015-03-02 177 views
2

我正在使用mockito 1.8.3,jacoco 0.72和maven 3.0.5 surefire插件(2.12.4)来执行单元测试并生成覆盖报告,它工作正常。Mockito,jacoco和surefire导致内存不足

随着越来越多的测试被添加,它开始不工作。在测试执行期间,我不断遇到内存不足的错误,并且找不到找出错误的方法。

我使用mockito作为嘲笑工具,大约有1800多个测试用例。如果我在测试阶段之前未使用“org.jacoco:jacoco-maven-plugin:prepare-agent”在maven测试期间运行jacoco,但工作正常,但只要我添加jacoco代理,就会发现与PermGen已满的OOO问题。

我已经通过修改MAVEN_OPTS(它不应该工作,因为surefire会分叉一个新的进程)和surefire argline参数在POM中添加到2GB的PermGen,但它没有什么帮助。

我试图通过向surefire插件添加参数发生OOO时获得核心转储,但从未在任何文件夹中看到转储文件。我怀疑我的JVM设置对于surefire插件不起作用,但不确定哪里出了问题。任何人都可以帮我一个忙吗?谢谢。

  <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> 

回答

4

你需要设置内存maven-surefire-plugin类似如下:

<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> 
+0

谢谢,它正在工作。不知道为什么我使用的“财产”格式不起作用。 – Skywolf 2015-03-03 06:27:48

1

如果您有jacoco与maven failsafe plugin一起配置,那么你就需要通过内存参数,以一个太:

<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>