java - How to add static member variables Jacoco Test Coverage? -


i have class following:

public class xconstants {      public static final int a_type = 1;     public static final int b_type = 2; } 

i using both variables in tests when examine test coverage jacoco shows %0 test coverage class. guess is, it's because never instantiate class, use static variables. tried creating instance , test coverage went %100. how can overcome problem?

the jacoco measures test coverage based on percentage of bytecode executed. declaring static final primitive or string constant creates no bytecode execute, it's entry inside constant pool. bytecode have here implicit default constructor, this:

aload_0 invokespecial object.<init> return 

so when don't call it, have 0%, when call it, have 100%.

my suggestion ignore problem. shouldn't try achieve 100% coverage no matter what. after doesn't guarantee anything: 100% covered code may contain serious bugs.


Comments