2008-09-09 120 views

回答

14

回答有关在源和仪器目录问题(这些可以切换到任何你的标准目录结构):

<property file="build.properties" /> 
<property name="source" location="src/main/java" /> 
<property name="test.source" location="src/test/java" /> 
<property name="target.dir" location="target" /> 
<property name="target" location="${target.dir}/classes" /> 
<property name="test.target" location="${target.dir}/test-classes" /> 
<property name="instr.target" location="${target.dir}/instr-classes" /> 

类路径:

<path id="compile.classpath"> 
    <fileset dir="lib/main"> 
    <include name="*.jar" /> 
    </fileset> 
</path> 

<path id="test.compile.classpath"> 
    <path refid="compile.classpath" /> 
    <pathelement location="lib/test/junit-4.6.jar" /> 
    <pathelement location="${target}" /> 
</path> 

<path id="junit.classpath"> 
    <path refid="test.compile.classpath" /> 
    <pathelement location="${test.target}" /> 
</path> 

首先你需要设置Ant可以找到Emma库:

<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" /> 

然后仪器代码:

<target name="coverage.instrumentation"> 
    <mkdir dir="${instr.target}"/> 
    <mkdir dir="${coverage}"/> 
    <emma> 
     <instr instrpath="${target}" destdir="${instr.target}" metadatafile="${coverage}/metadata.emma" mode="copy"> 
      <filter excludes="*Test*"/> 
     </instr> 
    </emma> 
    <!-- Update the that will run the instrumented code --> 
    <path id="test.classpath"> 
     <pathelement location="${instr.target}"/> 
     <path refid="junit.classpath"/> 
     <pathelement location="${emma.dir}/emma.jar"/> 
    </path> 
</target> 

然后运行目标与适当的VM参数,如:

<jvmarg value="-Demma.coverage.out.file=${coverage}/coverage.emma" /> 
<jvmarg value="-Demma.coverage.out.merge=true" /> 

最后生成报告:

<target name="coverage.report" depends="coverage.instrumentation"> 
    <emma> 
     <report sourcepath="${source}" depth="method"> 
      <fileset dir="${coverage}" > 
       <include name="*.emma" /> 
      </fileset> 
      <html outfile="${coverage}/coverage.html" /> 
     </report> 
    </emma> 
</target> 
+0

看起来不像你定义$ {}覆盖 – 2012-10-02 22:22:35

0

Emma 2.1引入了另一种方式o f获取运行时间覆盖信息(.ec文件)。可以远程请求来自计算机应用程序运行的计算机给定端口的数据。所以没有必要停止虚拟机。

要获得运行时的覆盖数据,你需要插入下面的代码片段在Ant脚本的测试,并生成覆盖报告的运行之间的文件:

<emma> 
    <ctl connect="${emma.rt.host}:${emma.rt.port}" > 
     <command name="coverage.get" args="${emma.ec.file}" /> 
     <command name="coverage.reset" /> 
    </ctl> 
</emma> 

其他步骤与艾玛2.0。他们在previous post

更多信息完美地描述关于艾玛2.1功能:http://sourceforge.net/project/shownotes.php?group_id=108932&release_id=336859

2

User Guide has a good example of how to set up your build script,这样你不仅单独从执行所构建的代码,但它也都包含在同一个<target>让你不不必运行一系列不同的目标,但是你可以做一些类似于ant emma tests的东西(例如,如果ant tests是你通常运行单元测试的方式)。

这里是他们的榜样:

<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="run" depends="init, compile" description="runs the examples" > 
    <emma enabled="${emma.enabled}" > 
     <instr instrpathref="run.classpath" 
      destdir="${out.instr.dir}" 
      metadatafile="${coverage.dir}/metadata.emma" 
      merge="true" 
     /> 
    </emma> 

    <!-- note from matt b: you could just as easily have a <junit> task here! --> 
    <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> 

    <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> 
相关问题