emma-maven-plugin 統計java覆蓋率插件

可參照網頁:中文:http://www.cnblogs.com/morebetter/archive/2013/06/26/3156756.html

http://www.ibm.com/developerworks/cn/opensource/os-cn-emma/index.html#download

英文:http://emma.sourceforge.net/ 需要翻牆

EMMA 核心插件 emma.jar 包,需要到官網上http://emma.sourceforge.net/ 下載。

1 EMMA 是一個開源、面向 Java 程序測試覆蓋率收集和報告工具。它通過對編譯後的 Java 字節碼文件進行插裝,在測試執行過程中收集覆蓋率信息,並通過支持多種報表格式對覆蓋率結果進行展示。 EMMA 所使用的字節碼插裝不僅保證 EMMA 不會給源代碼帶來“髒代碼”,還確保 EMMA 擺脫了源代碼的束縛,這一特點使 EMMA 應用於功能測試成爲了可能。
2 在測試中使用 EMMA 收集覆蓋率信息之前,需要從 EMMA 的網站上下載 emma.jar 包。在這個網站上還可以得到更多關於 EMMA 的資源。
3 EMMA 只能收集 Java 代碼的覆蓋率。

EMMA也可以和ant、maven等組合使用。需要下載相應的插件。

5 由於工作上經常用maven管理工程,本文主要講emma 和maven的組合使用方式。

主要參考:

http://mojo.codehaus.org/emma-maven-plugin/

http://mojo.codehaus.org/emma-maven-plugin/usage.html


需要下載兩個包:maven-emma-plugin-0.6.jar emma-stable-2.1.5320-lib.zip。

將zip解壓後,將maven-emma-plugin-0.6.jar 和emma.jar拷貝至{JAVA_HOME}jre\lib\ext文件夾下。

在工程的POM文件中添加以下依賴:

<build>
    <plugins>     
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <inherited>true</inherited>
        <configuration>
          <forkMode>once</forkMode>
          <reportFormat>xml</reportFormat>
          <classesDirectory>${project.build.directory}/generated-classes/emma/classes</classesDirectory>    
        </configuration>        
      </plugin>
    </plugins>
  </build>
以及

<reporting>    
    <plugins>  
      <plugin>      
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>emma-maven-plugin</artifactId>
        <version>1.0-alpha-3</version>
        <inherited>true</inherited>          
      </plugin>
      <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>surefire-report-maven-plugin</artifactId> 
        <inherited>true</inherited>
      </plugin>       
    </plugins>      
  </reporting>  
這個是激活產生report的,如果不加就不會產生。

另外,要注意放置的位置。

上文給出的鏈接將emma-maven-plugin也添加至plugins中。由於我們直接將其放置jre目錄下,所以不用加了。

添加完之後,在pom文件右上方點擊reimport。重新導入後在terminal中運行mvn emma:emma.

此時提示writing [xml] report to。。。

在target底下可以看到有site 和surefire文件夾,裏面即產生的report。打開index.html可以看非常詳細覆蓋率信息。其頁面如下:http://blog.chinaunix.net/uid-23741326-id-3716696.html 就不貼圖了。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章