3

I know that I am gonna have to use // CLOVER: OFF to turn off clover test coverage. I have read https://confluence.atlassian.com/display/CLOVER/Using+Source+Directives

I have added that line before my class declaration like:

// CLOVER: OFF public class SampleClass{ /* * Some definitions */ }

This thing worked for me yesterday and failing today. I am scratching my head trying to figure out a reason for failure.

But, my maven build failed because it did not meet the coverage percentage. I am using maven 3.3.9 and eclipse Neon for my project.

Anil Pediredla
  • 704
  • 2
  • 8
  • 20

2 Answers2

2

It's the space between CLOVER: and OFF which causes problems. You should use the directives exactly as it's described in the docs

// CLOVER:ON
// CLOVER:OFF

Are you trying to exclude whole file from instrumentation? If so you can simply exclude classes from instrumentation on a Maven or Eclipse level. Documentation links:

grzlew
  • 570
  • 3
  • 6
1

If you want to exclude one complete class from clover, you can do this in the pom configuration.

<configuration>
  <excludes>
    <exclude>**/SampleClass.java</exclude>
  </excludes>
</configuration>

If you want to exclude just one or more methods, use CLOVER:OFF/CLOVER:ON around them.

public class SampleClass {
    private int num;

    public SampleClass() {
        // intentionally left blank
    }

    // CLOVER:OFF
    public void setNum(int num) {
        this.num = num;
    }
    // CLOVER:ON
}

Beware of the fact that clover will still scan the excluded code if you have nothing left to scan in the class, hence the empty constructor.

Dudy
  • 17
  • 2
  • Hi, for me adding // CLOVER:OFF // CLOVER:ON does not work. What could be the possible cause for this? Do I need to add anything on my buid.gradle file for this purpose ? – Robi Mar 25 '20 at 17:34