java - No runtime coverage using emma, junit and ant -


i have following project structure:

  • src/com/dummy/abc.java
  • src_tests/come/dummy/abctest.java
  • build.xml

i need check coverage of code done tests using emma. reading emma + junit examples came conclusion report need following:

  1. compile 'src'
  2. compile 'src_tests'
  3. instrument compiled 'src_tests' => 'instrumented_src_tests'
  4. run junit on 'instrumented_src_tests' additional jvmarg

the problem step 4 should return kind of file used 'report' command should create report. i'm getting

emma-report:    [report] processing input files ...    [report] 1 file(s) read , merged in 67 ms    [report] nothing do: no runtime coverage data found in of data files 

~ edit i'm attaching build.xml

<?xml version="1.0" encoding="utf-8"?>  <project name="hell scream" default="all" basedir=".">     <property name="build.sources.dir" location="${basedir}/src"/>     <property name="build.sources.des" location="${basedir}/bin/classes"/>     <property name="test.sources.dir" location="${basedir}/src_test"/>     <property name="test.sources.des" location="${basedir}/bin/classes_test"/>     <property name="test.reports.des" location="${basedir}/reports-junit"/>     <property name="emma.sources.des" location="${basedir}/bin/classes_emma"/>     <property name="emma.reports.des" location="${basedir}/reports-emma"/>     <property name="emma.final.reports.des" location="${basedir}/reports-emma/final"/>     <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->     <path id="emma.lib" >         <fileset dir="/home/user1/desktop/emma-2.0.5312/lib">             <include name="*.jar"/>         </fileset>     </path>      <taskdef resource="emma_ant.properties" classpathref="emma.lib" />     <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->     <target name="clean-all">         <delete failonerror="false">             <fileset dir="${emma.final.reports.des}"/>             <fileset dir="${emma.reports.des}"/>             <fileset dir="${emma.sources.des}"/>             <fileset dir="${test.reports.des}"/>             <fileset dir="${test.sources.des}"/>             <fileset dir="${build.sources.des}"/>         </delete>     </target>     <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->     <target name="compile-sources">         <mkdir dir="${build.sources.des}"/>         <javac srcdir="${build.sources.dir}" includes="" excludes="" destdir="${build.sources.des}" listfiles="true" debug="true" includeantruntime="false"/>     </target>       <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->        <target name="compile-tests">         <mkdir dir="${test.sources.des}"/>         <javac srcdir="${test.sources.dir}" includes="" excludes="" destdir="${test.sources.des}" listfiles="true" debug="true" includeantruntime="false">             <classpath>                 <pathelement location="/home/user1/desktop/junit-4.10.jar"/>                 <pathelement location="${build.sources.des}"/>             </classpath>         </javac>     </target>      <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->     <target name="compile-emma-tests">         <emma enabled="true" >             <instr instrpath="${test.sources.des}" destdir="${emma.sources.des}" metadatafile ="${emma.reports.des}/instrumentation.emma" merge ="true"/>         </emma>     </target>     <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->      <target name="run-tests">         <mkdir dir="${test.reports.des}"/>         <junit haltonfailure="no" showoutput="yes" printsummary="true">                         <formatter type="plain" usefile="false" />             <formatter type="xml"/>             <classpath>                 <pathelement location="/home/user1/desktop/junit-4.10.jar"/>                 <pathelement location="${build.sources.des}"/>                   <pathelement location="${emma.sources.des}"/>                                 <path refid="emma.lib" />             </classpath>              <batchtest todir="${test.reports.des}" fork="true">                 <fileset dir="${emma.sources.des}"/>             </batchtest>                                     <jvmarg value="-demma.coverage.out.file=${emma.reports.des}/coverage.emma" />             <jvmarg value="-demma.coverage.out.merge=false" />         </junit>                 </target>     <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->     <target name="junit-tests-report">         <junitreport todir="${test.reports.des}">             <fileset dir="${test.reports.des}">                 <include name="test-*.xml"/>            </fileset>             <report format="frames" todir="${test.reports.des}/junit_reports"/>        </junitreport>     </target>      <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->     <target name="emma-tests-report">         <emma enabled="true" >             <report sourcepath="${build.sources.dir}">                     <fileset dir="${emma.reports.des}" >                     <include name="*.emma" />                 </fileset>                  <txt outfile="${emma.final.reports.des}/coverage.txt" depth="package" columns="class,method,block,line,name" />                 <xml outfile="${emma.final.reports.des}/coverage.xml" depth="package" />                 <html outfile="${emma.final.reports.des}/coverage.html" depth="method" columns="name,class,method,block,line" />             </report>         </emma>     </target>     <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->     <target name="all" depends="clean-all, compile-sources, compile-tests, compile-emma-tests, run-tests, junit-tests-report, emma-tests-report"/> </project> 

it trivial...

also, when using emma.sources.dest i'm getting on (only) test

run-tests:     [junit] running com.emma.test.mathtest     [junit] testsuite: com.emma.test.mathtest     [junit] tests run: 1, failures: 0, errors: 1, time elapsed: 0 sec     [junit] tests run: 1, failures: 0, errors: 1, time elapsed: 0 sec     [junit]      [junit]     caused error     [junit] illegal local variable table length 5 in method com.emma.test.mathtest.<init>()v     [junit] java.lang.classformaterror: illegal local variable table length 5 in method com.emma.test.mathtest.<init>()v     [junit]     @ java.lang.class.forname0(native method)     [junit]     @ java.lang.class.forname(class.java:188)     [junit]      [junit] test com.emma.test.mathtest failed 

~ solved add this:

<jvmarg value="-xx:-usesplitverifier"/> <jvmarg value="-demma.coverage.out.file=${emma.reports.des}/coverage.emma" /> <jvmarg value="-demma.coverage.out.merge=false" /> 

emma hasn't had stable release since 2005, , doesn't play newer versions of jdks. cobertura hasn't done new development since 2011. because of that, no longer recommend developers use emma or cobertura.

i've switched jacoco code coverage. started emma eclipse team, , actively being developed.

as stated in jacoco's mission statement.

[...]two of best , used available open source tools emma , cobertura. both tools not actively maintained original authors more , not support current java versions. due lack of regression tests maintenance , feature additions difficult.

therefore started jacoco project provide new standard technology code coverage analysis in java vm based environments. [...]

the nice thing jacoco works in wide variety of environments, , don't have instrument code after compiling. instrumentation takes place tests being executed. looks this:

<jacoco:coverage destfile="${target.dir}/jacoco.exec">     <junit>         [...]     </junit> </jacoco> 

you use <jacoco:coverage> print coverage report.

do have use emma? if not, might better luck getting working using jacoco.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -