Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give test coverage for private constructor of a final class in sonarqube?

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();
     }
 }
like image 689
Albin Avatar asked Sep 07 '25 02:09

Albin


1 Answers

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):

  • update for SonarQube (https://jira.sonarsource.com/browse/SONARJAVA-2608) is supposed to be in not yet released SonarJava plugin version 5.1
  • update for Jenkins Plugin (https://github.com/jenkinsci/jacoco-plugin/commit/d04b50962a022b615d5085271f1696d9f6080198) is committed but also not yet released
like image 55
Godin Avatar answered Sep 09 '25 17:09

Godin