1
votes

I am newbie to use Emma. I am trying to add emma ant task for JUnit test case for modules in EAR project. I have few question here.

  • Should I use instrumented class for packaging my EAR projet?
  • What is good way to add emma ant task for junit? Should I use emmarun:on-th-fly mode or offline mode? For JUnit should I use fork or no fork?

I am using Emma Offline mode and Junit with fork. Here is my build.xml

<!--Target and task for EMMA -->
<taskdef resource="emma_ant.properties" classpathref="Emma.libraryclasspath" />
<target name="emma" description="turns on EMMA's instrumentation/reporting" >
    <property name="emma.enabled" value="true" />
    <mkdir dir="${out.instr.dir}" />
    <property name="emma.filter" value="" />
 </target>

<target name="test" depends="init, compile" description="Run JUnit Test cases under emma environment">
    <!-- Emma instrumentation -->
    <emma enabled="${emma.enabled}" verbosity="verbose">
        <instr instrpath="${class.dir}"
                     destdir="${out.instr.dir}"        
                     metadatafile="${coverage.dir}/metadata.em"
                     merge="true" 
                     mode="copy">
            <filter value="${emma.filter}" />
        </instr>
    </emma>

    <!-- JUnit Start -->
    <junit printsummary="yes" fork="yes">
        <test name="com.hf.platform.authorizer.WebTxnAuthorizerTest" todir="${test.report.dir}">
            <formatter type="xml"/>
        </test>
        <classpath>
            <path refid="HFPlatformWeb.classpath"/>
            <path refid="Emma.libraryclasspath"/>
        </classpath>
        <jvmarg value="-Demma.coverage.out.file=${coverage.dir}/coverage.ec" />
        <jvmarg value="-Demma.coverage.out.merge=false" />
    </junit>
    <!-- Junit End -->

    <emma enabled="${emma.enabled}" verbosity="verbose">
        <report>
            <sourcepath>
                <dirset dir="${basedir}">
                    <include name="src"/>
                    <include name="test-src"/>
                </dirset>
             </sourcepath>
            <fileset dir="${coverage.dir}">
                <include name="*.em"/>
                <include name="*.ec"/>
            </fileset>
        <xml outfile="${coverage.report.dir}/report.xml" />
        <txt outfile="${coverage.report.dir}/report.txt" />
        <html outfile="${coverage.report.dir}/report.html" />
        </report>
    </emma>

</target>

When I ran it for one test, it is not generating any report. But when i ran same unit test with EclEmma it gives correct output.

1
eclEmma uses jacoco, which is a somewhat never approach to code coverage, which also has ant tasks. - oers

1 Answers

2
votes

In above example we need to make sure following two things

  1. The file path for metadatafile and coverage report file that is .ec, .em or .emma file should be absolute or relative to project. e.g.
  2. For running java/junit task sandwiched between the instrumentation and report task, it must use instrumented class file path. e.g.

    <classpath> <pathelement location="${out.instr.dir}" /> <path refid="Emma.libraryclasspath"/> <path refid="HFPlatformEJB.classpath"/> </classpath>