`

Emma: Quick Reference

    博客分类:
  • Java
阅读更多

Introduction

EMMA is an open-source toolkit for measuring and reporting Java code coverage. EMMA distinguishes itself from other tools by going after a unique feature combination: support for large-scale enterprise software development while keeping individual developer's work fast and iterative. Every developer on your team can now get code coverage for free and they can get it fast!

Chances are, you've come here already knowing what coverage is all about and are, in fact, wondering what EMMA offers and why it is worth checking out. Explore the rest of this site to see why.

EMMA features at a glance

  • EMMA can instrument classes for coverage either offline (before they are loaded) or on the fly (using an instrumenting application classloader).
  • Supported coverage types: class, method, line, basic block. EMMA can detect when a single source code line is covered only partially.
  • Coverage stats are aggregated at method, class, package, and "all classes" levels.
  • Output report types: plain text, HTML, XML. All report types support drill-down, to a user-controlled detail depth. The HTML report supports source code linking.
  • Output reports can highlight items with coverage levels below user-provided thresholds.
  • Coverage data obtained in different instrumentation or test runs can be merged together.
  • EMMA does not require access to the source code and degrades gracefully with decreasing amount of debug information available in the input classes.
  • EMMA can instrument individial .class files or entire .jars (in place, if desired). Efficient coverage subset filtering is possible, too.
  • Makefile and ANT build integration are supported on equal footing.
  • EMMA is quite fast: the runtime overhead of added instrumentation is small (5-20%) and the bytecode instrumentor itself is very fast (mostly limited by file I/O speed). Memory overhead is a few hundred bytes per Java class.
  • EMMA is 100% pure Java, has no external library dependencies, and works in any Java 2 JVM.

Use EMMA in WebLogic

First of all, there is little chance that you will be able to use the on-the-fly mode (emmarun) with a full-blown J2EE container. The reason lies in the fact that many J2EE features require specialized classloading that will happen outside of EMMA instrumenting classloader. The server might run fine, but you will likely get no coverage data.

Thus, the correct procedure is to instrument your classes prior to deployment (offline mode). Offline instrumentation always follows the same compile/instrument/package/deploy/get coverage/generate reports sequence. Follow these steps:

  1. use EMMA's instr tool to instrument the desired classes. This can be done as a post-compilation step, before packaging. However, many users also find it convenient to let EMMA process their jars directly (either in-place, using overwrite mode, or by creating separate instrumented copies of everything, in fullcopy mode);
  2. do your J2EE packaging as normal, but do not include emma.jar as a lib at this level, that is, within your .war, .ear, etc;
  3. locate whichever JRE is used by the container and copy emma.jar into its <jre dir>/lib/ext directory. If that is impossible, add emma.jar to the server classpath (in a server-specific way);
  4. deploy your instrumented classes, .jars, .wars, .ears, etc and exercise/test your J2EE application via your client-side testcases or interactively or whichever way you do it;
  5. to get a coverage dump file, you have three options described in What options exist to control when EMMA dumps runtime coverage data?. It is highly recommended that you use coverage.get control command with the ctl tool available in v2.1.

Example, Offline Mode with Weblogic

This example tests the PokerHand class via a simple web app, where an HTML file is used to invoke the PokerHand class via a servlet. The build steps are as follows:

  1. The Ant build compiles the Java source and instruments the classes.
  2. The instrumented classes and web resources are bundled into a WAR file.
  3. Tomcat must have access to the Emma jar. One way is to copy emma.jar to the $JAVA_HOME/jre/lib/ext directory, where JAVA_HOME is the JVM used by Tomcat.
  4. The user deploys the WAR file, starts Tomcat, and tests via the HTML page.
  5. When Tomcat is shutdown, "coverage.ec" is written to $TOMCAT_HOME/bin.
  6. The above file is copied to the example directory so that the report can be generated.

Again, the resulting report is similar, where the coverage level is a direct reflection of the number of tests explored via the browser.
This example exercises PokerHand.java via the PokerHandServlet, using Emma to report on the code-coverage.

It uses the Emma's "offline mode" to instrument the Java classes before building a war file.  After exercising the servlet, Emma is used to generate a report.

Run Build.xml
this will build ./dist/pokerhand.war, and this step may depend on emma_ant.jar.

 

<?xml version="1.0"?>

<project name="PokerHand" default="build" basedir=".">

 <property name="classes.dir" value="${basedir}/classes" />
 <property name="coverage.dir" value="${basedir}/coverage" />
 <property name="dist.dir" value="${basedir}/dist" />
 <property name="instr.dir" value="${basedir}/classes_instr" />
 <property name="lib.dir" value="${basedir}/lib" />
 <property name="src.dir" value="${basedir}/src" />
 <property name="web.dir" value="${basedir}/web" />

 <target name="init">
  <mkdir dir="${classes.dir}" />
  <mkdir dir="${instr.dir}" />
  <mkdir dir="${coverage.dir}" />
  <mkdir dir="${dist.dir}" />
  <path id="run.classpath">
   <pathelement location="${classes.dir}" />
  </path>
 </target>

 <target name="compile" depends="init" description="typical Java compile">
  <javac debug="on" srcdir="${src.dir}" destdir="${classes.dir}" classpath="${lib.dir}/junit.jar;${lib.dir}/servlet-api.jar" />
 </target>

 <target name="clean" description="cleans directories">
  <delete dir="${classes.dir}" />
  <delete dir="${classes_instr.dir}" />
  <delete dir="${coverage.dir}" />
  <delete dir="${instr.dir}" />
  <delete dir="${dist.dir}" />
 </target>

 <!-- path element used by EMMA taskdef below: -->
 <path id="emma.lib">
  <pathelement location="${lib.dir}/emma.jar" />
  <pathelement location="${lib.dir}/emma_ant.jar" />
 </path>

 <!-- this loads <emma> and <emmajava> custom tasks: -->
 <taskdef resource="emma_ant.properties" classpathref="emma.lib" />

 <target name="emma" description="turns on EMMA's instrumentation/reporting">
  <property name="emma.enabled" value="true" />
  <property name="out.instr.dir" value="${basedir}/outinstr" />
  <mkdir dir="${out.instr.dir}" />
  <property name="emma.filter" value="" />
 </target>

 <target name="instrument" depends="init, compile" description="instruments the Java classes">
  <emma enabled="true">
   <instr instrpathref="run.classpath" destdir="${instr.dir}" metadatafile="${coverage.dir}/metadata.emma" merge="true">
   </instr>
  </emma>
 </target>

 <target name="build" depends="instrument" description="builds the war file">
  <zip destfile="${dist.dir}/pokerhand.war">
   <zipfileset dir="${instr.dir}" prefix="WEB-INF/classes" />
   <zipfileset dir="${web.dir}" />
  </zip>
 </target>
</project>

 

Copy emma.jar file to $DOMAIN_HOME/lib, and deploy war file into Weblogic.

Run app.

Copy coverage.ec from $DOMAIN_HOME to this directory.

Run run.bat (Windows) or run.sh (Linux).
java -classpath emma.jar emma report -r html -in coverage.ec,coverage/metadata.emma -sourcepath src

Sample report

Sample code

Password: hzwangbing.spaces.live.com

Emma-Test.zip

Download (Namipan) Download (SkyDrive)

分享到:
评论

相关推荐

    Emma:Emma内存和Mapfile分析器

    Emma内存和Mapfile分析器(Emma) 基于任意链接器映射文件进行静态(即,最坏情况)的内存消耗分析。 它会生成大量的.csv文件,这些文件易于过滤和后期处理。 可选的.html和markdown报告以及整洁的数字可以帮助您...

    emma:Emma是一款以人性化的方式与trevor知识导航器进行通信的应用程序

    **Emma应用程序概述** Emma是一款专为用户与Trevor知识导航器进行互动设计的应用程序,其核心特性在于提供了一个更加人性化、用户友好的界面。通过Emma,用户可以更轻松地查询信息、获取解答,以及利用Trevor的知识...

    emma:电磁采矿阵列。 在加密侧信道攻击的情况下用于电磁辐射的分布式分析的工具

    电磁采矿阵列(EMMA) EMMA是一种框架,用于捕获和攻击电子设备发出的电磁辐射的痕迹,以便获得加密密钥或其他敏感数据。 安装 推荐的安装EMMA的方法是通过venv : $ cd &lt; emma&gt; $ python -m venv env $ source ...

    emma:基于报价的Scala DSL,用于可扩展的数据分析

    Emma支持最新的数据流引擎,例如和作为后端协处理器。产品特点用于可扩展数据分析的DSL通过类型嵌入。 相反,Emma基于报价(类似于 )。 这种方法有两个好处。 首先,它允许在DSL中重用Scala原生的声明性构造。 ...

    emma:hchdshdjhs

    标题中的"emma:hchdshdjhs"似乎是一种命名方式,但没有明确的IT相关含义。描述中的内容同样没有提供具体的信息。不过,标签指出了"Python",这是一个广泛使用的编程语言,我们的讨论将主要围绕Python展开。 Python...

    emma-stable-2.1.5320-lib.zip

    《Emma:一个强大的Java代码覆盖率工具》 Emma是一款广泛使用的Java代码覆盖率工具,它能够帮助开发者在测试过程中了解代码的覆盖率情况,确保测试的全面性和有效性。标题中的"emma-stable-2.1.5320-lib.zip"是Emma...

    emma:一个教育性的爱好项目,用于了解基本服务操作。 反向代理,服务路由,蓝绿色部署,故障注入等等!

    emma是一项功能全面的网关服务,旨在作为反向代理,适用于为您的Web应用程序启动实验,蓝/绿部署和金丝雀测试。 emma可以作为前端或后端应用程序的网关服务安装。 emma可以在接收HTTP / HTTPS或WebSockets流量的...

    the introduction to emma

    《Emma:明确模型检测管理器介绍》一文详细介绍了EMMA (Explicit Model Checking Manager) 这一工具,该工具是针对模型检测过程中自动化程度不足的问题而设计的。模型检测作为一种自动化的技术,其在实际应用中的...

    emma.jar emma_ant.jar emma_device.jar

    EMMA,全称为Emma Metrics for Measuring and Managing,是一个广泛使用的开源工具,专门设计用于评估Java应用程序的代码覆盖率。在软件开发过程中,测试是至关重要的一步,而代码覆盖率则是衡量测试质量的重要指标...

    emma_ant.jar,emma.jar合包

    标题中的"emma_ant.jar,emma.jar合包"指的是将Emma工具的两个主要组件——`emma.jar`和`emma_ant.jar`合并在一起的压缩文件。Emma是一个广泛使用的Java代码覆盖率工具,它提供了对Java应用程序单元测试的覆盖率分析...

    CruiseControl与EMMA集成的方法与步骤

    关键的配置是 `schedule` 元素中的 `goal` 参数,它应包含 `-Dmaven.test.skip=true|emma:emma`,这样 Maven 就会在跳过常规测试的同时执行 EMMA 的覆盖率分析。 ```xml &lt;!-- ... --&gt; &lt;!-- ... --&gt; ...

    EMMA 粉末级配分析

    EMMA(Engineering Materials Microstructure Analysis)是一款用于粉末颗粒级配分析的专业软件,它在材料科学、化工、矿业等领域有着广泛的应用。粉末颗粒级配是指粉末中不同粒径颗粒的比例和分布,这一特性对粉末...

    Emma_for_Android

    ### 使用Emma进行Android程序代码覆盖率测试 #### 一、引言 在软件开发过程中,确保代码的质量至关重要。其中,代码覆盖率是一种衡量测试充分性的指标,它可以帮助开发者了解哪些部分的代码已被测试覆盖,哪些部分...

    emma单元测试覆盖率

    EMMA,全称为Emma Metrics for Java,是一款开源的代码覆盖率工具,专为Java应用程序提供精确的测试覆盖率报告。 EMMA的核心功能在于收集和分析执行单元测试后的代码覆盖数据,包括行覆盖率、分支覆盖率、方法覆盖...

    Java emma工具

    ### Java Emma工具详解 #### 一、Emma工具简介 Emma是一款强大的开源代码覆盖率工具,用于度量Java应用程序的代码覆盖率。Emma支持多种测试框架,并且能够很好地与持续集成环境和其他开发工具结合使用。通过Emma,...

    ant junit emma 示例工程。

    Ant、JUnit和Emma是三个关键的工具,它们在软件测试和代码覆盖率分析中扮演着重要角色。Ant是一个流行的Java构建工具,JUnit是Java语言的单元测试框架,而Emma则用于代码覆盖率报告。 Ant是一种基于XML的构建工具,...

    emma-2.0.5312-lib.zip

    标题 "emma-2.0.5312-lib.zip" 提供的信息表明,这是一个与 Emma 相关的软件库的压缩文件,版本号为 2.0.5312。Emma 是一个广泛使用的 Java 软件覆盖率工具,它帮助开发者测量和验证程序测试的有效性,确保代码被...

    emma统计手工测试或Ui测试覆盖率——几个工具文件

    标题中的“emma统计手工测试或Ui测试覆盖率”指的是Emma,一个开源的Java代码覆盖率工具,它可以帮助开发者衡量单元测试和集成测试对代码的覆盖程度。Emma可以与JUnit、TestNG等测试框架配合使用,提供类、方法、行...

Global site tag (gtag.js) - Google Analytics