Reputation: 2069
I have a util class which is final and I have added one private constructor for hide the default public one. How I can get the coverage for this class in sonarqube with jacoco coverage report and build in Jenkins?
public final class Util {
// My contructor
private Util() {
super();
}
}
Upvotes: 4
Views: 4616
Reputation: 10574
According to JaCoCo changelog such private empty no-argument constructors are automatically filtered out starting from JaCoCo version 0.8.0. Changelog also notes:
Tools that directly read exec files and embed JaCoCo for this (such as SonarQube or Jenkins) will provide filtering functionality only after they updated to this version of JaCoCo.
Announcement of release of JaCoCo version 0.8.0 states:
Tools that directly read exec files (which is not a final report) and embed JaCoCo for generation of report will provide filtering functionality only after they updated to this version of JaCoCo. So please follow/wait/etc respective vendors such as
- SonarQube - https://jira.sonarsource.com/browse/SONARJAVA-2608
- Eclipse EclEmma - https://bugs.eclipse.org/bugs/show_bug.cgi?id=529391
- Jenkins - https://github.com/jenkinsci/jacoco-plugin
Reports generated by corresponding version (0.8.0) of integrations developed as part of JaCoCo project by us (Ant Tasks, Maven Plugin and Command Line Interface) provide filtering functionality.
As of today (30 Jan 2018):
Upvotes: 5
Reputation: 1325976
If you configure sonar to use cobertura (and not jacoco) for the code coverage, you could simply exclude that method from code coverage.
That seems easier than writing an artifical test case using reflection.
Upvotes: 0