Jacoco code coverage for custom sonar rules - does not show coverage

And created test cases for my custom rules as given in the link.

The custom rules i am running in CI/CD and when i run jacoco on the custom rules with the test cases as per the above guidelines, jacoco is not recognizing the test cases and shows zero coverage.

Test cases are written as given here sonar-java/AvoidAnnotationRuleTest.java at master · SonarSource/sonar-java · GitHub usisng CheckVerifier.newVerifier()

But jacoco does not instruement these test cases and provides the coverage as zero.

How to make jacoco recognize these tests as 100% coverage.

Any help from the community, pls

Hello @sivak ,

Thank you for your patience. I’m not sure to understand what you are asking.

The java-custom-rule-example maven project is supposed to be autonomous, and able to compute the code coverage by default.

When executing mvn clean install sonar:sonar at the root of this project, I get coverage for each rule… For instance, for the AvoidAnnotationRule, I get the coverage correctly displayed on my local instance of SonarQube (see the green bars):

However, SonarQube do not display coverage on the test code. Are you sure you are looking at the good code? You won’t have anything display on the test class AvoidAnnotationRuleTest.java, but this is by design. We do not support this case.