Skip to content

UsageTipsAndTricks

Marc R. Hoffmann edited this page Oct 27, 2016 · 4 revisions

This is a collection of tips and some not so obvious tricks for using JaCoCo. The ideas have been collected and verified in different projects where JaCoCo helps to monitor test coverage. This should become part of JaCoCo documentation.

Name Your Test Sessions

Do you run a modular build with several separate test suites? In this case set the sessionid property of the JaCoCo agent or the coverage Ant task with e.g. the name of the test component. This information will then be included in the report (e.g. on the "Session" page of the HTML report) and clearly document the source of the execution data shown in the report. The JaCoCo build itself uses this technique, see its session page.

Group your Reports

Reports may not only be grouped by Java packages. With group tags within the report Ant task arbitrary hierarchies can be defined above the package level. This allows to reflect your product structure (modules, bundles, features etc.) and results in comparable summaries for the individual groups. The report for JaCoCo itself is structures in this way to get separate values for each bundle.

Read Class/Source Files from Archives

The JaCoCo Ant tasks fully utilize Ant's resource collection types. Any resource collection might serve as input for class files, source files or execution data. So for example it is possible to collect source files from source archives. The following example picks the Java sources of the Equinox OSGi implementation from the corresponding source archive:

<sourcefiles>
    <zipfileset includes="**/*.java">
        <fileset dir="${target.plugins.dir}" includes="org.eclipse.osgi.source_*.jar" />
    </zipfileset>
</sourcefiles>

Coverage Reports Without Execution Data

You can create a coverage report without specifying execution data at all - which will result in 0% coverage. Why should anyone do this? The report still provides some interesting metrics about the code base, for example the effective lines of code. When compiled with debug information this is possible even if don't have the corresponding sources.

Narrow the Scope

TODO