I'm using Jacoco to find the code coverage of unit tests with ANT but the report isn't generated and I get this error sequence:
[jacoco:report] Loading execution data file C:\JUnit\apache-ant-1.10.1\jacoco.ex
ec
[jacoco:report] Writing bundle 'Test' with 566 classes
[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.
[jacoco:report] Execution data for class com/!!/DataExtractorHelper does not match.
[jacoco:report] Execution data for class com/!!/WelcomeLetter does not match.
[jacoco:report] Execution data for class com/!!/WelcomeLetterABCD does not match.
I've read these answers but none seemed to help me solve the problem.
jacoco: For report generation the same class files must be used as at runtime
I compiled all classes on Eclipse and used the ANT build tool to perform code coverage on these classes. I do make use of some external jars due to some dependencies and they've been compiled on jdk 1.8.0_101 and I'm using jdk 1.8.0_111 (I tried solving this error by using jdk 1.8.0_101 but I got the same errors)
It has been mentioned that the class ID might change in Eclipse vs Oracle JDK compilation. Therefore I also checked this case by compiling some basic classes on Eclipse and used the jdk + ANT to find the code coverage. It worked in this case. There is no compilation taking place in the code coverage task. The .class files just need to be checked for coverage.
All the classes mentioned in the errors have been compiled on eclipse before testing for the code coverage.
I've tried using the offline instrumentation tool as a workaround to the persistence framework being used but it still gives me these errors. All the classes mentioned above in the errors are present in the Instrumented classes folder. ${dest.dir}
This is my build.xml at the moment.
<target name="instrument">
<delete dir="${dest.dir}"/>
<mkdir dir="${dest.dir}"/>
<jacoco:instrument destdir="${dest.dir}">
<fileset file="D:/NEON/HW/!!/module/!!/bin" includes="**/*.class"/>
<fileset file="D:/NEON/HW/!!/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/!!/config/"/>
<pathelement path="C:/JUnit/apache-ant-1.10.1/InstrClasses"/>
</classpath>
<sysproperty key="jacoco-agent.destfile" file="jacoco.exec"/>
<test name="Fully qualified classname"/>
<formatter type="plain"/>
<formatter type="plain" usefile="false" />
<batchtest fork="yes" todir="${report.dir}">
<fileset dir="${src.dir}" includes="Fully qualified classname.java"/>
</batchtest>
</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/!!/module/!!/bin"/>
<fileset dir="D:/NEON/HW/!!/testprojects/!!/bin"/>
</classfiles>
<sourcefiles>
<fileset dir="D:/NEON/HW/!!/module/!!/src"/>
<fileset dir="D:/NEON/HW/!!/testprojects/!!/src"/>
</sourcefiles>
</structure>
<csv destfile="${report.dir}/report.csv" />
</jacoco:report>
</target>
Questions: 1.Will there be any difference in the bytecode generated by compilers based on jdk 1.8.0_101 and jdk 1.8.0_111? Can incremental updates change bytecode? Or is the difference only significant during major version updates?
2.Why am I still getting this error even after offline instrumentation has been implemented? Am I missing out on any declaration in the code? I've tried to keep the format of the code as similar to that of the example provided in the jacoco documentation here.
- I've also noticed that the number of classes being instrumented(614) differs from the number of classes being added to the Test bundle (566) when both contain the same classpaths. Could that be of any consequence?