0

I have a class with @UtilityClass annotation. However, if I won't set the fields as static, sonarqube complains about 0% coverage for these fields. What is interesting, @UtilityClass annotation automatically adds static fields when it is compiled. So basically .class files are the same for @UtilityClass with static or without static fields. So why sonarqube shows different results if .class files are the same...?

import lombok.experimental.UtilityClass;

@UtilityClass
public class Test {

    public final static String TEST = "test";
}

This class has the same .class file after compilation as this one:

import lombok.experimental.UtilityClass;

@UtilityClass
public class Test {

    public final String TEST = "test";
}
Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
user2455862
  • 585
  • 10
  • 26
  • Does this answer your question? [How to ignore lombok.@UtilityClass for Jacoco?](https://stackoverflow.com/questions/56272632/how-to-ignore-lombok-utilityclass-for-jacoco) – aksappy Aug 04 '21 at 16:35
  • @aksappy No, this question is how to make jacoco ignore auto generated classes. I have this configured. My question is: Why sonarqube shows different results for classes which have the same compiled content (the same .class files)? – user2455862 Aug 04 '21 at 16:38

1 Answers1

0

Most probably it’s because Sonarqube’s unit test metrics as they are using a different methods to calculate the coverage. So there is no guarantee that both coverage results will be identical. You can check Sonarqube’s metrics regarding the unit tests

https://docs.sonarcloud.io/digging-deeper/metric-definitions/#tests

Abdullah Ceylan
  • 134
  • 1
  • 6