¿Cómo puedo generar informes de cobertura de código Emma usando Ant?


¿Cómo configuro una tarea Ant para generar informes de cobertura de código Emma?

Author: Rob Spieldenner, 2008-09-10

3 answers

Para responder preguntas sobre dónde se encuentran los directorios fuente e instrumentados (estos se pueden cambiar a cualquiera que sea su estructura de directorios estándar):

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

Classpaths:

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

Primero necesitas configurar donde Ant puede encontrar las bibliotecas de Emma:

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

Luego importa la tarea:

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

Luego instrumente el código:

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

Luego ejecute un destino con los argumentos de VM adecuados como:

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

Finalmente genere su informe:

<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>
 14
Author: Rob Spieldenner,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-10-19 16:48:57

La Guía del Usuario de tiene un buen ejemplo de cómo configurar su script de compilación para que no solo separe el código instrumentado de la ejecución, sino que también esté todo contenido en el mismo <target> para que no tenga que ejecutar una serie de objetivos diferentes, sino que en su lugar puede hacer algo como ant emma tests (si ant tests fue como normalmente ejecutó sus pruebas unitarias, por ejemplo).

Aquí está su ejemplo:

<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>
 2
Author: matt b,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2008-10-14 15:36:51

Emma 2.1 introduce otra forma de obtener información de cobertura en tiempo de ejecución (archivo.ec). Se puede solicitar de forma remota los datos desde el puerto dado del equipo donde se ejecuta una aplicación instrumentada. Así que no hay necesidad de detener VM.

Para obtener el archivo con los datos de cobertura en tiempo de ejecución, debe insertar el siguiente fragmento en su script Ant entre la ejecución de sus pruebas y la generación del informe de cobertura:

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

Otros pasos son similares a Emma 2.0. Están perfectamente descritos in previous post

Más información sobre las características de Emma 2.1: http://sourceforge.net/project/shownotes.php?group_id=108932&release_id=336859

 0
Author: wheleph,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:32:33