java - jacoco code coverage report generator showing error : "Classes in bundle 'Code Coverage Report' do no match with execution data" -
i generating jacoco report using jacoco:report tag. getting errors :
[jacoco:report] classes in bundle 'code coverage report' no match execution data. report generation same class files must used @ runtime. [jacoco:report] execution data class xxxxx not match. [jacoco:report] execution data class yyyyy not match.
the ant report target looks :
<target name="report"> <jacoco:report> <executiondata> <file file="${jacocoexec.dir}/${jacocoexec.filename}"/> </executiondata> <!-- class files , optional source files ... --> <structure name="code coverage report"> <classfiles> <fileset file="./jar/abc.jar"/> </classfiles> <sourcefiles> <fileset dir="./code/src"/> </sourcefiles> </structure> <!-- produce reports in different formats. --> <html destdir="${jacoco.report.dir}"/> </jacoco:report> </target>
the abc.jar
generated using ./code/src
only. why giving such errors. idea?
you getting error related classid. concept described in detail @ jacoco docs-site. http://www.eclemma.org/jacoco/trunk/doc/classids.html. key step supporting multiple versions of class (an appserver example) in same jvm.
copying part part of here visibility.
what class ids , how created?
class ids 64-bit integer values, example 0x638e104737889183 in hex notation. calculation considered implementation detail of jacoco. ids created crc64 checksum of raw class file.
what can cause different class ids?
class ids identical exact same class file (byte-by-byte). there couple of reasons why might different class files. first compiling java source files result in different class files if use different tool chain:
different compiler vendor (e.g. eclipse vs. oracle jdk)
different compiler versions
different compiler settings (e.g. debug vs. non-debug)
also post-processing class files (obfuscation, aspectj, etc.) typically change class files. jacoco work if use same class files runtime analysis. tool chain create these class files not matter.
even if class files on file system same there possible classes seen jacoco runtime agent different anyways. typically happens when java agent configured before jacoco agent or special class loaders pre-process class files. typical candidates are:
- mocking frameworks
- application servers
- persistence frameworks
the same page covers possible solutions.
what workarounds exist deal runtime-modified classes?
if classes modified @ runtime in setup there workarounds make jacoco work anyways:
- if use java agent make sure jacoco agent specified @ first in command line. way jacoco agent should see original class files.
- specify classdumpdir option of jacoco agent , use dumped classes @ report generation. note loaded classes dumped, i.e. classes not executed @ not show-up in report not covered.
- use offline instrumentation before run tests. way classes instrumented jacoco before runtime modification can take place. note in case report has generated original classes, not instrumented ones.
edited on 22-02-2017
how use offline instrumentation: use below task provided daniel atallah.
//additional sourcesets can added jacocoofflinesourcesets needed project.ext.jacocoofflinesourcesets = [ 'main' ] task dojacocoofflineinstrumentation(dependson: [ classes, project.configurations.jacocoant ]) { inputs.files classes.outputs.files file outputdir = new file(project.builddir, 'instrumentedclasses') outputs.dir outputdir dofirst { project.delete(outputdir) ant.taskdef( resource: 'org/jacoco/ant/antlib.xml', classpath: project.configurations.jacocoant.aspath, uri: 'jacoco' ) def instrumented = false jacocoofflinesourcesets.each { sourcesetname -> if (file(sourcesets[sourcesetname].output.classesdir).exists()) { def instrumentedclasseddir = "${outputdir}/${sourcesetname}" ant.'jacoco:instrument'(destdir: instrumentedclasseddir) { fileset(dir: sourcesets[sourcesetname].output.classesdir, includes: '**/*.class') } //replace classes dir in test classpath instrumented 1 sourcesets.test.runtimeclasspath -= files(sourcesets[sourcesetname].output.classesdir) sourcesets.test.runtimeclasspath += files(instrumentedclasseddir) instrumented = true } } if (instrumented) { //disable class verification based on https://github.com/jayway/powermock/issues/375 test.jvmargs += '-noverify' } } } test.dependson dojacocoofflineinstrumentation
now generate report using "gradlew test jacocotestreport"
command.
Comments
Post a Comment