Create a new metric

CodeCover is delivered with four implemented coverage metrics:

If these metrics don't suite your needs, you can implement your own metric.
This metric can use the data collected by the instrumented code in order to provide coverage statistics.

Implementing the CoverageMetric interface

In order to create a new metric, you have to implement the org.codecover.metrics.coverage.CoverageMetric interface. This interface contains methods to calculate the coverage for MAST nodes. The abstract class org.codecover.metrics.coverage.AbstractCoverageMetric provides default implementations for many methods in the interface.

You still have to implement the getCoverageLocal() and getHints() methods.

The getCoverageLocal() methods return the coverage for a single MAST element. If your metric doesn't create coverage information for a specific MAST element, you can return CoverageResult.NULL in this overload.

The getHints() methods return additional coverage hints. If you don't want to return additional coverage hints, you can return noHints which is an empty Set<CoverageHint>.

Creating a plugin

In order to create a plugin with your new metric, you have to create a class implementing org.codecover.model.extensions.Plugin. You can use org.codecover.model.extensions.AbstractPlugin for an easier implementation.

In order to create a plugin, you have to put all necessary .class files into a .jar file with a file called codecover-plugin.xml which has the following structure:

<plugin xmlns=""
        name="example.metric" version="4.2"
  <depends name="org.codecover" version="0.1" />

Here it is assumed that your plugin class has the name example.metric.MetricPlugin and you want to call your plugin example.metric with the version number 4.2. The plugin will require CodeCover with a plugin ABI version of 0.x with x >= 1.


Example metric

In order to compile the example you might have to adjust the path of the codecover-core.jar in the build.xml file.

The example is an implementation of a method coverage. Only methods with at least one basic statement will be considered.