emma-maven-plugin always executes test cases twice

這是碎碎唸
如果同時要出Emma Code Coverage跟Surefire Test report的話,一定要跑2次 Unit Test,聽起來很合理,但其實根本就不用。
只要在Surefire執行前先將test classes做instrument,這様測出來的就是具有coverage的unit test.

<plugin>
 <groupId>org.sonatype.maven.plugin</groupId>
 <artifactId>emma-maven-plugin</artifactId>
 <version>1.1</version>
 <inherited>true</inherited>
 <executions>
  <execution>
   <id>instrument</id>
   <phase>process-classes</phase>
   <goals>
    <goal>instrument</goal>
   </goals>
  </execution>
 </executions>
</plugin>
<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-surefire-plugin</artifactId>
 <version>2.4.3</version>
 <inherited>true</inherited>
 <configuration>
  <forkMode>once</forkMode>
        <reportFormat>xml</reportFormat>
  <classesDirectory>${project.build.directory}/generated-classes/emma/classes</classesDirectory>
 </configuration>
</plugin>

這様跑完就㑹產生coverage.em, coverage.ec等產生Code Coverage Report所需要的東西。

而jira上也提出這個問題很久了…就是他X的沒人解決,
Allow generating reports outside the emma:emma goal

現在只好偷偷用emma4it-maven-plugin,單獨來跑report,只是不能出現在project reports裡

<plugin>
 <groupId>org.sonatype.maven.plugin</groupId>
 <artifactId>emma4it-maven-plugin</artifactId>
 <version>1.3</version>
 <executions>
  <execution>
   <id>report</id>
   <phase>post-integration-test</phase>
   <goals>
    <goal>report</goal>
   </goals>
   <configuration>
    <sourceSets>
     <sourceSet>
      <directory>${project.build.sourceDirectory}</directory>
     </sourceSet>
    </sourceSets>
   </configuration>
  </execution>
 </executions>
</plugin>

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料