1

I have a Gradle project with the JaCoCo plugin applied to it. When I run my tests and create a jacocoTestReport I get this classes not matching error

[ant:jacocoReport] Classes in bundle 'e-services' do no match with execution data. For report generation the same class files must be used as at runtime.
[ant:jacocoReport] Execution data for class eservices/model/persistence/Event does not match.

The classes should match as I'm doing a clean -> build -> test locally. I suspect the mismatch comes from the fact that I'm using jackson.map.ObjectMapper to create an object from a JSON and somehow this causes the classId stored in jacoco's .exec file not match the compiled class id.

My test uses the Event class extensively and still I get 0% coverage due to class mismatch:

import eservices.model.persistence.Event;
event = mapper.readValue(json, Event.class);
event.setTenId(TenIds.getInternalId());

Is there a way to get coverage from this scenario?

leecheve
  • 51
  • 5
  • Is the question http://stackoverflow.com/q/20219936/783510 related to your problem? – Philipp Claßen Jul 24 '15 at 17:49
  • No, I do have a jacoco agent running and capturing data. I also have the resulting .exec file and the compiled classes in place, the problem is jacoco says the captured data for Event.class doesn't match the compiled class Event.class although it is the exact same compiled class running. – leecheve Jul 27 '15 at 16:07
  • @user3470347 Are you using a mock library (e.g., PowerMock) that would dynamically modify the bytecode of the Event class? If yes, that is a known incompatibility: JaCoCo relies on the checksum of the runtime bytecodes matching the checksum of the bytecodes it uses for report generation. Try the classdumpdir option to the JaCoCo javaagent to ensure the class bytes are identically, and (optionally) just use those bytecodes for your report generation. – Brett Kail Jul 27 '15 at 17:28
  • I'm using JPA (EclipseLink), specifically `group: 'org.eclipse.persistence', name: 'javax.persistence', version: '2.0.5')` – leecheve Jul 28 '15 at 21:58
  • @bkail thanks for your suggestion, I dug up more about JPA and JaCoCo and found it has the exact issue you described. I'll post it as answer to this question. – leecheve Jul 29 '15 at 02:17
  • @leecheve Glad you were able to find a solution. – Brett Kail Jul 29 '15 at 02:47

1 Answers1

2

This is a JaCoCo Known limitation as JaCoCo relies on the checksum of the runtime bytecodes matching the checksum of the bytecodes it uses for report generation. Typically it happens when you have two libraries instrumenting bytecodes, like PowerMock and JaCoCo, or JPA and JaCoCo.

This is referenced in the following JaCoCo issue Coverage is missing a class that was in fact tested #193 and it is labeled as 'wontfix' 'known limitation'

leecheve
  • 51
  • 5