Skip to content

CoverageDataModel

Marc R. Hoffmann edited this page Aug 18, 2024 · 2 revisions

Purpose

The coverage data model is the public API between the inner code coverage mechanics of JaCoCo and various integrations which processes the coverage information. Widely used integrations are:

  • Reporting: The built-in reports (HTML, CSV, XML) are built on top of the coverage API whereby the XML schema closely follows the coverage data model.
  • IDE Integration: Eclipse and Intellij plug-ins use JaCoCo APIs to reflect coverage information directly in the IDE UI.

Current Model (since 0.5.0)

Assumptions

The model was created under the following assumptions:

  • Focus is on class files primarily compiled from Java source code, resulting in the following assumptions:
  • A source file may result in multiple class files (inner classes, secondary classes, anonymous classes).
  • Each class file results from at most one source file.
  • The qualified name of a class is unique within a bundle. Different versions of a class can only be analyzed in separate bundles.

Entities

classDiagram
    class ISourceNode
    <<Abstract>> ISourceNode
    class IBundleCoverage
    class IPackageCoverage
    class ISourceFileCoverage
    class IClassCoverage
    class IMethodCoverage
    ISourceNode <|-- IClassCoverage
    ISourceNode <|-- IMethodCoverage
    ISourceNode <|-- ISourceFileCoverage
    IPackageCoverage "*" *-- IBundleCoverage
    IClassCoverage "*" *-- IPackageCoverage
    ISourceFileCoverage "*" *-- IPackageCoverage
    IMethodCoverage "*" *-- IClassCoverage
Loading
Entity Identity within Scope References
IBundleCoverage none, only application specific IPackageCoverage*
IPackageCoverage name package name within bundle IClassCoverage*, ISourceFileCoverage*
ISourceFileCoverage name local file name within package -
IClassCoverage id global, name within bundle IMethodCoverage*
IMethodCoverage name + desc not used -

Analysis Process

The analysis process is performed in two main steps for each bundle:

  1. Analyze all class files of a bundle one after the other. For each visited class file a IClassCoverage object holding 0..n IMethodCoverage objects is created. In the process Java debug information is used to assign each instruction and branch of a method to a line of source code (assuming all methods in a class are solely compiled from the same source file).
  2. Create a IBundleCoverage instance by with the following algorithm:
    1. Aggregate all IClassCoverage objects with the same source reference into a ISourceFileCoverage object.
    2. Aggregate all IClassCoverage and ISourceFileCoverage with the same package reference to a IPackageCoverage object.
    3. Aggregate all IPackageCoverage objects into a IBundleCoverage instance.

When aggregating ISourceNode model elements referring to the same source file line coverage counters cannot simply be added. Instead coverage has to be evaluated line by line as instructions from different classes or methods my result from the same line of source code.

Clone this wiki locally