標籤:java 測試 覆蓋率 emma 外掛程式
可參照網頁:中文: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 代碼的覆蓋率。
4 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 就不貼圖了。
emma-maven-plugin 統計java覆蓋率外掛程式