All the fields were the same(Reported accurately) except for the LINE_MISSED and LINE_COVERED!
Report created via EclEmma reports the number of lines covered accurately whereas the report created by Jacoco mentions 0 in both the fields.
Why is this happening? Is it supposed to happen?
Now, I compiled the classes in Eclipse itself and copied them to the point where ant starts creating the jar using the .class files.
Surprisingly, the file created now has the line numbers mentioned correctly.
Why is this happening?
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false">
<classpath>
<pathelement location="C:/JUnit/apache-ant-1.10.1/src"/>
<path refid="classpath"/>
</classpath>
<compilerarg value="-Xlint"/>
<compilerarg line="-Xmaxerrs 10000" />
</javac>
</target>
<target name="jar">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
Documentation also includes an Ant example which shows how to properly configure the javac task for debug information.Why does the coverage report not show line coverage figures?
JaCoCo is based on class files analysis. To calculate line coverage class files must contain line number attributes. For this your code must be compiled with debug information.
I'm testing another project wherein I receive this warning during report creation:
[jacoco:report] Classes in bundle 'Test' do no match with execution data. For report generation the same class files must be used as at runtime.
[jacoco:report] Execution data for class com/**/AccountDetails does not match.
and the same warning for 3 more classes resulting in partial coverage details being copied to the report.
I googled it and found an answer on stack overflow suggesting that the versions used to compile the classes and create the report might be different.
I'm using a few external jars(Because of some dependencies). The .class files within these jars might have been compiled on 1.8.0_101 and I'm using 1.8.0_111
Originally I had tried it with 1.8.0_101 itself but I received the same error.
What might be the cause of this error?
What I've done:
<jacoco:instrument destdir="${dest.dir}">
<fileset dir="D:/NEON/HW/!!/bin" includes="**/*.class"/>
</jacoco:instrument>
Does the location of the instrumented classes(dest.dir) need to be included in both the coverage task and report creation task or only one of them?
<target name="cov-test" depends="jar">
<mkdir dir="${report.dir}"/>
<jacoco:coverage>
<junit fork="true" forkmode="once" showoutput="true" printsummary="on" enabletestlistenerevents="true">
<test name="com.!!.DocumakerJunit"/>
<classpath>
<path refid="ALL.jars"/>
<path refid="classpath"/>
<pathelement location="C:/JUnit/JARS/2017-06-21/config/"/>
<pathelement location="C:/JUnit/apache-ant-1.10.1/InstrClasses"/> <-- LOCATION OF INSTRUMENTED CLASSES
</classpath>
</junit>
</jacoco:coverage>
</target>
<target name="cov-report" depends="cov-test">
<jacoco:report>
<executiondata>
<fileset file="jacoco.exec" />
</executiondata>
<structure name="Test">
<classfiles>
<!-- DOES THE LOCATION OF THE INSTRUMENTED CLASSES BE MENTIONED HERE OR LOCATION OF ORIGINAL CLASS FILES??-->
</classfiles>
<!--<sourcefiles>
</sourcefiles>-->
</structure>
<csv destfile="${report.dir}/report.csv" />
</jacoco:report>
</target>
http://www.jacoco.org/jacoco/trunk/doc/offline.html
I read this page but I'm not entirely clear on where the jacocoagent.jar must be specified with respect to the coverage and report generation tasks and where the instrumented / original classes must be used.
Any additions to the code mentioned above are most welcome and very much appreciated. Thanks.
Hi Marc,
I've translated the code to fit the format of offline instrumentation from what I could observe in the example you provided, but I'm still receiving the same errors.
"[jacoco:report] Classes in bundle 'Test' do no match with execution data. For report generation the same class files must be used as at runtime.
[jacoco:report] Execution data for class com/**/AccountDetails does not match."
<target name="instrument">
<jacoco:instrument destdir="${dest.dir}">
<fileset file="D:/NEON/HW/!!/projects-framework/module/!!/bin" includes="**/*.class"/>
<fileset file="D:/NEON/HW/!!/projects-framework/testprojects/!!/bin" includes="**/*.class"/>
</jacoco:instrument>
</target>
<target name="cov-test" depends="instrument">
<mkdir dir="${report.dir}"/>
<jacoco:coverage>
<junit fork="true" forkmode="once" showoutput="true" printsummary="on" enabletestlistenerevents="true">
<classpath>
<path refid="ALL.jars"/>
<path refid="classpath"/>
<pathelement location="C:/JUnit/jacoco-0.7.9/lib/jacocoagent.jar"/>
<pathelement location="C:/JUnit/JARS/2017-06-21/config/"/>
<pathelement path="C:/JUnit/apache-ant-1.10.1/InstrClasses"/>
</classpath>
<sysproperty key="jacoco-agent.destfile" file="jacoco.exec"/>
<test name="com.!!.ABCJunit"/>
</junit>
</jacoco:coverage>
</target>
<target name="cov-report" depends="cov-test">
<jacoco:report>
<executiondata>
<file file="jacoco.exec" />
</executiondata>
<structure name="Test">
<classfiles>
<fileset dir="D:/NEON/HW/!!/bin"/>
<fileset dir="D:/NEON/HW/!!/bin"/>
</classfiles>
<sourcefiles>
<fileset dir="D:/NEON/HW/!!/src"/>
<fileset dir="D:/NEON/HW/!!/src"/>
</sourcefiles>
</structure>
<csv destfile="${report.dir}/report.csv" />
</jacoco:report>
</target>
I can't seem to find the bug. Please help point out anything wrong in the code? What can be done to improve this?
Thanks Marc, for taking the time out to answer these questions. Really appreciate it.
Hi Marc,
I've translated the code to fit the format of offline instrumentation from what I could observe in the example you provided, but I'm still receiving the same errors.
"[jacoco:report] Classes in bundle 'Test' do no match with execution data. For report generation the same class files must be used as at runtime.
[jacoco:report] Execution data for class com/**/AccountDetails does not match."