Coverage Highlighting

Calculating Coverage

The Diffblue Cover IntelliJ IDEA plugin can calculate coverage from existing tests and use this information to avoid generation of tests for code which is already covered. Users can select which coverage measurement tool they would like to use in:

Tools -> Diffblue Cover -> Coverage -> Coverage Engine

which can be found under File -> Settings (Windows/Linux) or IntelliJ IDEA -> Preferences (macOS).

We recommend using the IntelliJ coverage measurement by default.

The existing coverage is computed first as this makes the test generation stage faster. Optionally, the change in coverage after the tests have been written can be calculated. By default, the plugin will compute the change in coverage, but this can be turned off via the Compute Changes in Coverage tick-box in the Coverage tab in Preferences/Settings.

If the Compute Changes in Coverage feature is enabled, then once the tests have been written (and the coverage tool re-run), markers will appear in the gutter of the editor to indicate changes in coverage.

Coverage Runners

IntelliJ Coverage Runner

The IntelliJ IDE has the capability to calculate coverage out-of-the-box. If the IntelliJ coverage engine is selected in the plugin preferences, Diffblue Cover will automatically produce a Run configuration to run the relevant tests when you request an analysis. All tests within the selected module will be run. During analysis, you will notice that the IntelliJ coverage UI is displayed. This may occur twice if you have requested that coverage change is computed.


To use JaCoCo as your project's coverage provider, ensure your project is configured to be able to run the JaCoCo Maven plugin from the command line.

You can test whether your project is configured to run JaCoCo by running the following command from your terminal in your project root directory:

mvn org.jacoco:jacoco-maven-plugin:prepare-agent test -fn

If your project can run the above command, you will be able to see project coverage marking in your IDE editor window.

Coverage Marking

When invoking Write Tests from the Diffblue Cover IntelliJ Plugin, the following steps are performed (steps three and four will only be run if the Compute Changes in Coverage option is selected via Preferences/Settings):

1) The Diffblue Cover Plugin will run your coverage provider before beginning analysis.

2) It will then write tests for your requested method, class, or package.

3) It will then run your coverage provider a second time.

4) A comparison between existing and new coverage is calculated and published to the UI.

This comparison will be marked in your IDE Editor window, with each line having four possible states existing, new, and uncovered (or unknown).

existing refers to lines that were previously covered by existing unit tests. These lines are marked with a green dot by default.

new refers to lines that are now covered by Diffblue Cover unit tests. These lines are marked with a blue dot by default.

uncovered refers to lines that were not covered either before or after a Diffblue Cover analysis. These lines are marked with a grey dot by default.

unknown refers to any line that is not coverable, such as lines that are empty or contain only syntactical elements. It also refers to any lines for which a coverage status could not be determined. These lines are not marked by default.

Note: colors for any coverage state can be changed in the Diffblue Cover plugin preferences. This can be accessed via Tools -> Diffblue Cover -> Coverage under Preferences/Settings.

Run Write Tests again on the same method and any previously blue dots will change to green, signalling that they are now known to be existing coverage.

Right-clicking on any of the coverage dots will remove them from all of the files.

Known Issues

Duplicate Tests Generated

When using JaCoCo (either via the built-in coverage engine or by configuring the IntelliJ coverage runner) or the IntelliJ coverage runner in Tracing mode, there's a chance of duplicate tests being generated.

Internally, partially covered lines are treated as uncovered when setting the exclude lines. Both these modes (JaCoCo or IntelliJ in Tracing mode) produce these partially covered lines.

This manifests itself in cases like this:

public class Foo {
  public boolean simple(final int value) {
    if (value > 5) {
      return true;
    } else {
      return false;

With a test that looks like this:

public class TestFoo {
  public void testSimple() {
    Assert.assertTrue(new Foo().simple(6));

The if statement is partially covered and so will generate test cases for both branches despite one of the branches already being covered.

results matching ""

    No results matching ""