JaCoCo and missed coverage of private default constructor

mat_boy picture mat_boy · Mar 11, 2016 · Viewed 11.4k times · Source

I'd like to see an example to prevent JaCoCo to report private empty constructors as non-covered code in a Java class.

In the maven plugin configuration I have

   <rule>
     <element>CLASS</element>
       <excludes>
         <exclude>JAVAC.SYNTHCLASS</exclude>
         <exclude>JAVAC.SYNTHMETH</exclude>
       </excludes>
     </element>
   </rule>

Isn't there something similar for the constructor?

Answer

Jesus Zavarce picture Jesus Zavarce · Mar 11, 2016

This is not supported. The official documentation says:

Filters for Code where Test Execution is Questionable or Impossible by Design

  • Private, empty default constructors - assuming no calls to it
  • Plain getters and setters
  • Blocks that throw AssertionErrors - Entire block should be ignored if a condition (if !assertion throw new AssertionError)

see also : https://github.com/jacoco/jacoco/issues/298

Update: This was fixed in https://github.com/jacoco/jacoco/pull/529 and should be in 0.8.0.