使用 Jackson.map.ObjectMapper 创建的对象的 JaCoCo 0% 覆盖率

JaCoCo 0% coverage for objects created with Jackson.map.ObjectMapper

我有一个应用了 JaCoCo 插件的 Gradle 项目。当我 运行 我的测试并创建一个 jacocoTestReport 我得到这个 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.

classes 应该匹配,因为我正在执行清理 -> 构建 -> 本地测试。我怀疑不匹配是因为我正在使用 jackson.map.ObjectMapper 从 JSON 创建对象,这会导致 classId存储在 jacoco 的 .exec 文件中与编译的 class id 不匹配。

我的测试广泛使用事件 class,但由于 class 不匹配,我的覆盖率仍然为 0%:

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

有没有办法覆盖这种情况?

这是 JaCoCo 的已知限制,因为 JaCoCo 依赖于运行时字节码的校验和与它用于生成报告的字节码的校验和相匹配。通常,当您有两个库检测字节码时,如 PowerMock 和 JaCoCo,或 JPA 和 JaCoCo,就会发生这种情况。

这在以下 JaCoCo 问题 Coverage is missing a class that was in fact tested #193 中被引用并且被标记为 'wontfix' 'known limitation'