Search code examples
javacode-coveragejacoco-maven-pluginprivate-constructor

JaCoCo and missed coverage of private default constructor


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?


Solution

  • 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.