`
pengtyao
  • 浏览: 403288 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Emma in Ant for offline

阅读更多
1. 下载emma lib
http://sourceforge.net/projects/emma/files/emma-release/2.0.5312/emma-2.0.5312.zip/download
我下载的是emma-2.0.5312.zip

2. 解压emma-2.0.5312.zip,里面有一个lib目录,内含2个jar文件:
emma.jar
emma_ant.jar: 包含了Emma taskdefs
这两个文件都要放在项目的lib库里,可以在build.xml里设置一个path element以方便ant调用

<!-- directory that contains emma.jar and emma_ant.jar: -->
  <property name="emma.dir" value="${basedir}/../lib" />

  <path id="emma.lib" >
    <pathelement location="${emma.dir}/emma.jar" />
    <pathelement location="${emma.dir}/emma_ant.jar" />
  </path>

  <taskdef resource="emma_ant.properties" classpathref="emma.lib" />


2. offline模式,先给需要进行代码覆盖的class文件加字节码

<target name="emma" description="turns on EMMA instrumentation/reporting" >
    <property name="emma.enabled" value="true" />
    <!-- EMMA instr class output directory: -->
    <property name="out.instr.dir" value="${basedir}/outinstr" />
    <mkdir dir="${out.instr.dir}" />
  </target>


<target name="emma.add.bytecode" depends="init, compile" description="Emma add bytecode to classes" >
    <emma enabled="${emma.enabled}" >
      <instr instrpathref="run.classpath"
             destdir="${out.instr.dir}" 
             metadatafile="${coverage.dir}/metadata.emma"
             merge="true">
        <filter includes="classes name or classes package which you want to coverage">
        <filter excludes="classes name or classes package which you do not want to coverage">
        <filter value="+classes, -classes">
        <filter file="filter.txt">
      </instr>
    </emma>
  </target>

注:
(1) instr是emma的字节码插入器,它是在编译好的classes目录里把需要进行coverage的class文件插入bytecode,并copy到
${out.instr.dir}目录,生成metadata.emma文件
(2) filter用于匹配哪些类需要或者不需要进行coverage,可以用includes\excludes\value\file这几种方式,支持*匹配符。file方式里的文件可以是这样的:
#-表示这个类不需要coverage
-com.foo.test.*
#+表示需要
+com.foo.*

3. 运行代码,或者是运行junit来执行代码,这里是用emma下载包里自带的example为例是执行代码,注意加的两个jvmarg,把运行代码的覆盖率文件coverage.emma生成,以及生成的内容是merge方式

<target name="run" depends="emma.add.bytecode" description="Execute code or run junit test">
    <java classname="Main" fork="true" >
      <classpath>
       <pathelement location="${out.instr.dir}" />
        <path refid="run.classpath" />
        <path refid="emma.lib" />
      </classpath> 
      <jvmarg value="-Demma.coverage.out.file=${coverage.dir}/coverage.emma" />
      <jvmarg value="-Demma.coverage.out.merge=true" />
    </java>
  </target>


4. 生成report,根据前两步的metadata.emma和coverage.emma两个文件,生成txt和html两种格式的report
  <target name="emma.report" depends="run" description="Generate the emma report">
    <emma enabled="${emma.enabled}" >
      <report sourcepath="${src.dir}" >
        <fileset dir="${coverage.dir}" >
          <include name="*.emma" />
        </fileset>

        <txt outfile="${coverage.dir}/coverage.txt" />
        <html outfile="${coverage.dir}/coverage.html" />
      </report>
    </emma>
  </target>


<report>的sourcepath用于指定源代码目录,这样可以在html里看到哪些代码被coverage了。
其他的一些参数:
depth: 指定report细到哪一层,可以为以下的值:

    * all
    * package
    * source
    * class
    * method

encoding: 指定report的字符集
参考:
http://emma.sourceforge.net/userguide_single/userguide.html
http://emma.sourceforge.net/reference_single/reference.htm

原文地址:http://hi.baidu.com/lettoo/blog/item/da98a0038edaaae708fa93cd.html
分享到:
评论
1 楼 cancan7 2012-11-23  
您好,为什么我下载的emma_ant.jar中没有Emma taskdefs文件呢,而且海报这个错误:
D:\Workspaces\ant_junit_emma\CodeCoverage\make\build.xml:61: taskdef A class needed by

class com.vladium.emma.emmajavaTask cannot be found: org/apache/tools/ant/taskdefs/Java
using the classloader AntClassLoader[D:\Workspaces\ant_junit_emma\CodeCoverage\
lib\emma.jar;D:\Workspaces\ant_junit_emma\CodeCoverage\lib\emma_ant.jar]

Total time: 0 seconds

期待您的尽快回复,谢谢

相关推荐

    Unity Offline Render

    Offline Render is an easy to use, realtime capture plugin for Unity. It allows you to capture the game view to a multi-channel OpenEXR or multiple PNG files, supporting not just the final output image...

    Offline Explorer使用方法

    Offline Explorer 使用方法 Offline Explorer 是一款功能强大的网站整站下载器,能够快速下载整个网站的内容。下面将详细介绍 Offline Explorer 的使用方法和技巧。 安装和设置 首先,安装 Offline Explorer 并...

    解决adb error: device offline也包含4.2.2版本fastboot

    然而,有时我们可能会遇到“device offline”的错误提示,这通常意味着ADB无法识别或连接到设备。本篇将详细介绍如何解决“adb error: device offline”问题,并重点讨论在Android 4.2.2版本下使用ADB及Fastboot工具...

    AI2 Offline Companion.apk

    AI2 Offline Companion.apk

    CapsWriter-Offline.zip

    8. **打包构建工具**:如果CapsWriter是一个复杂的项目,可能还会有`setup.cfg`、`MANIFEST.in`等文件,用于配置构建和打包过程。 9. **许可证信息**:开源项目通常会有`LICENSE`文件,声明软件的使用许可条款。 ...

    Mifare offline cracker GUI (mfocGUI) v2.9

    Mifare offline cracker GUI (mfocGUI) v2.9

    OE - Offline Explorer Enterprise 注册机

    Offline Explorer Enterprise 注册机 内含 MetaProducts.Offline.Explorer.Enterprise.6.6.3970 对于以后的版本,注册机可用的概率非常大。 Offline Explorer 是非常好用的离线浏览工具,推荐使用!

    Install_Docker_offline_离线安装Docker_Install-Docker-Offline.zip

    Install_Docker_offline_离线安装Docker_Install-Docker-Offline

    DriverPack-Offline_data_

    【标题】"DriverPack Offline 数据包" 【描述】"fhbngbejdkgjnfndbgnghn" 这段描述看似随机的字符组合,无法直接解析出具体的信息,但我们可以推测它可能是某种加密或者混淆后的信息,通常在安全传输或隐藏数据时会...

    Android studio离线组件offline-gmaven-stable.part3.rar

    Android studio离线组件最新版本的 Google Maven 依赖项offline-gmaven-stable,文件分割成 三个 压缩包,必须集齐 三个 文件后才能一起解压一起使用: Android studio离线组件offline-gmaven-stable.part1.rar ...

    离线浏览器Portable Offline Browser

    离线浏览器Portable Offline Browser是一款专为用户在无网络环境下访问网站设计的软件工具。它允许用户将整个网站或其中特定部分下载到本地计算机上,以便在没有互联网连接时也能浏览内容。这款国外开发的优秀离线...

    offline explorer enterprise 7.5破解版

    offline explore enterprise·7.5 解压后直接双击根目录下的exe即可

    Android studio离线组件offline-gmaven-stable.part1.rar

    Android studio离线组件最新版本的 Google Maven 依赖项offline-gmaven-stable,文件分割成 三个 压缩包,必须集齐 三个 文件后才能一起解压一起使用: Android studio离线组件offline-gmaven-stable.part1.rar ...

    网站绐终显示app_offline.htm的解决方法

    其中一个常见的问题是,在测试或部署阶段,无论何时尝试访问网站的任何页面,都只会看到一个提示页面:“This application is currently offline. To enable the application, remove the app_offline....

    AI2Offline_x64.exe

    AI2Offline_x64.exe

    emma java统计代码覆盖率

    此外,Emma 可与 Makefile 和 Ant 构建工具集成,便于在大型项目中使用。其高效的性能是另一个显著优点,尤其是在处理大量代码时。 Emma 提供两种运行模式:On-the-fly 和 Offline。 1. On-the-fly 模式:这种模式...

    Offline NT Password and Registry Editor

    1. `install.bat`:这是一个批处理文件,通常用于自动化执行一系列命令,可能是用来运行“Offline NT Password and Registry Editor”的安装或启动过程。 2. `bd050303.bin`:这可能是一个二进制文件,可能是程序的...

    IAR Offline License Generator v1.4 by unis

    IAR Offline License Generator v1.4 by unis用于IAR注册

    harbor-offline-installer-v2.8.3 安装包

    harbor-offline-installer-v2.8.3安装包

    Android studio离线组件offline-gmaven-stable.part2.rar

    Android studio离线组件最新版本的 Google Maven 依赖项offline-gmaven-stable,文件分割成 三个 压缩包,必须集齐 三个 文件后才能一起解压一起使用: Android studio离线组件offline-gmaven-stable.part1.rar ...

Global site tag (gtag.js) - Google Analytics