SonarQube 6.7.2: coverage on new code not available.

3,176 views
Skip to first unread message

Ujjwal

unread,
Mar 16, 2018, 7:08:49 PM3/16/18
to SonarQube
Hello All,

I am having issues with getting "coverage on new code" working. It is always shown '-'

Setup:
SonarQube 6.7.2 (developer Edition, with branch analysis)
Project is build with Java8 and mvn
Gitlabs as SCM (Git SCM plugin is installed in sonar)

We use CI/CD for our deployments and our practice is to build and scan each commit from any branch for the project.
When code/project is sent for very first time for analysis to sonar, off-course I don't expect to show me "coverage on new code". But, for every subsequent commits, code is sent for analysis, this is where I expect (naturally) to show me "coverage on new code". We have numerous git branches for the project and each branch is submitted for analysis multiple times a day. I am not sure what are we missing. 

Note- First I though this might be as sonar is not able to get SCM/blame information. I have looked for blame information and sonar is able to pick it. I can tell that by looking at committer's name in code shown in sonar.

We also want "Branch Analysis" feature for developer edition and have setup patterns for Long living  and short living branches, but I only see Master(Main) branch in the project -> Administration -> branches. What I am missing.

Can anyone please point us in right direction ?

G. Ann Campbell

unread,
Mar 20, 2018, 11:36:12 AM3/20/18
to SonarQube
Hi,

Okay, so let's get the obvious stuff out of the way first: 

* You say your build uses Maven, so this may be a silly question, but your project includes Java code?

* And you are feeding in a coverage report?

* Anything interesting or relevant-seeming your analysis log?


Ann

ujjwal...@8x8.com

unread,
Mar 20, 2018, 2:36:08 PM3/20/18
to SonarQube
Ann,

Thanks for the response. Please check reply below.

* You say your build uses Maven, so this may be a silly question, but your project includes Java code? -- Yes, its all java code.

* And you are feeding in a coverage report? -- Yes coverage report is being sent. We use Jacoco. I can see overall coverage and code smells, etc..

* Anything interesting or relevant-seeming your analysis log? -- I dont see anything extra-ordinary.We do submit same project over an over again from different branches of code.
    e.g 1. I have a project called ABCservice. For my initial scan I submit code from master branch.
          2. Now, other developer creates a feature branch and makes some changes and   commits the code to git. 
          3. Now, our CI system will pick this commit from feature branch and send it to same (ABCService) project in sonar for analysis.
          4. At this point, Sonar does show overall coverage but does not show any coverage on new code. I am assuming this is where branch analysis should kick-in.
              Note: We did define long living and short-living branches.

Please let me know you would like any other info.

G. Ann Campbell

unread,
Mar 21, 2018, 7:34:50 AM3/21/18
to SonarQube
Hi,

Are you seeing other 'new code' measures? Also, what's your leak period setting?

I don't quite follow your description of how you handle branches, but from what I gather, it sounds a bit off, with you overlaying the master branch on a regular basis with analysis of branches?


Ann

ujjwal...@8x8.com

unread,
Mar 21, 2018, 4:52:04 PM3/21/18
to SonarQube

Ann,

I am not seeing any "New Code" measures.viz, coverage and duplication. see screen capture below.




For the description of branching, sorry wanst clear before. Let me attempt it again.

 1. I have a project called ABCservice. In Git I have master branch, where my initial code is.
 2. For my first scan in sonar, I submit code from master branch. Scan results show few issues.
 3. Now, other developer creates a feature branch from master and makes some changes and  commits the code to git. Now, I have two branches in git, Master and feature.
 4. Our CI system is tied with git and will pick this commit( from feature branch) and send it to sonar for analysis.
     Here I have not changed my app_name. Same name (ABCService) for project in sonar is used for analysis.
 5. At this point, Sonar does show overall coverage, but does not show any coverage on new code. I am assuming this is where branch analysis should kick-in. long living and short-living branches are defined in sonar. Also, in sonar.properties we are sending git branch name and parameter ( sonar.branch.name and sonar.branch.target).

May be my assumption is incorrect, but In terms of 'new code',I am expecting that sonar would show me diff from last analysis from master branch and current analysis from feature branch.
  
Can you please help us understand, how to setup branch analysis correctly. Sonar documentation did not clear my doubts.

G. Ann Campbell

unread,
Mar 22, 2018, 12:11:25 PM3/22/18
to ujjwal...@8x8.com, SonarQube
Hi,

Thanks for the followup. I think I have a better understanding now of what's going on.

When you analyze a branch as a branch you're not going to see anything updated in the main project. That's part of the point of branch analysis; being able to get an understanding of the quality of code that's not in master yet.

Once you merge your branch and reanalyze master, then 'new code' metrics come into play.

Regarding setting up branch analysis, without more detail on what was unclear to you in the docs I won't be able to go any further. BTW, you can find your branches here:

HTH,
Ann




---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/LMBn0IfJrDU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/e2b56fea-a23b-4e3a-8e19-b10f9e714b14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

thibaut...@gmail.com

unread,
Apr 3, 2018, 8:01:09 AM4/3/18
to SonarQube
@G. Ann Campbell, in the branch analysis, there is no coverage even if the report is sent.  Only issues are reported. It's on purpose?

G. Ann Campbell

unread,
Apr 3, 2018, 10:52:43 AM4/3/18
to thibaut...@gmail.com, SonarQube
Hi,

Let's say it's on purpose but not optimal. In fact, we do want to get to the point where we report coverage and duplications on short-lived branches. We're just not there yet.


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/LMBn0IfJrDU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.

brhe...@gmail.com

unread,
Apr 23, 2018, 9:46:47 AM4/23/18
to SonarQube
Hi Ann-
Thanks for the update.  That would be a major feature improvement for us.
Beau
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.

shru...@yahoo.com

unread,
Apr 25, 2018, 11:35:23 AM4/25/18
to SonarQube
Hi Ann,

This issue is exactly the same issue we have been looking into. Can you please clarify how does "New code coverage" work or point me to documentation on this? Based on above explanation, it seems that new code coverage does not apply to changesets in the same branch. Is my understanding correct?

Thanks,
Shruthi

G. Ann Campbell

unread,
Apr 25, 2018, 11:45:17 AM4/25/18
to shru...@yahoo.com, SonarQube
Hi Shruthi,

I'm not clear on what you're asking, so I'll just reiterate that short-lived branch analysis does not include the generation of metrics for coverage or duplications.


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/f59ac6d4-33ff-455c-af67-d6ddde2f576f%40googlegroups.com.

shru...@yahoo.com

unread,
Apr 25, 2018, 12:04:48 PM4/25/18
to SonarQube
Sorry, I was not clear.

Lets say I have a feature branch that has couple of developers working and checking in changes. After analyzing the branch, SonarQube shows the overall code coverage. Then a developer checks in a lot of new code. When the analyzer runs the next time (on the same feature branch), does it show the coverage for the newly checked in code under "New Code Coverage" metrics?

Thanks,
Shruthi

G. Ann Campbell

unread,
Apr 25, 2018, 1:21:43 PM4/25/18
to shru...@yahoo.com, SonarQube
Hi Shruthi,

So first, let's distinguish what a "feature branch" is. Our expectations are that maintenance is done in long-lived branches (where coverage is calculated) and new features are developed in short-lived "feature branches". So... Will coverage on new code be shown in a "feature branch"? No, not by our definition.

But let's set that aside and say we're dealing with long-lived branches, then yes, coverage on new code would be shown in the scenario you describe. 


HTH,
Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/7cfe811c-2e89-4936-b482-b9b637d7f010%40googlegroups.com.

shru...@yahoo.com

unread,
Apr 25, 2018, 1:25:57 PM4/25/18
to SonarQube
Thanks, Ann.

One last question - how does SonarQube know if a branch is short-lived or long-lived? Is there a way to configure this in SonarQube? 

G. Ann Campbell

unread,
Apr 25, 2018, 1:34:27 PM4/25/18
to Shruthi Berikai, SonarQube
Hi,

Good question. There's a branch name regex. From the docs

By default, branches that have names starting with either "branch" or "release" will be treated as long-lived.

This is configurable at project and global levels.


Ann 



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/75f5dc89-e07e-4a56-bf00-2dd1ac52ca27%40googlegroups.com.

shru...@yahoo.com

unread,
Apr 25, 2018, 1:49:39 PM4/25/18
to SonarQube
Thanks a lot, Ann! I think I was missing this bit of info. I see this plugin is available in SonarQube 7.1 version. We are currently on SonarQube 6.7.2. Does it mean that 6.7.2 will not support "new code coverage" in long-lived branches? If yes, can you please clarify how the "New code coverage" works in 6.7.2?

Let me know if I am not clear.

Thanks again!

G. Ann Campbell

unread,
Apr 25, 2018, 1:50:48 PM4/25/18
to Shruthi Berikai, SonarQube
Hi,

The developer edition is available for 6.7.* and works just the same as it does in 7.1 w/r/t coverage. 


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/48570c31-600b-468b-8e87-15e2eb9bdadc%40googlegroups.com.

shru...@yahoo.com

unread,
Apr 25, 2018, 2:25:19 PM4/25/18
to SonarQube
Awesome! 

If the Branch plugin is not even installed/configured, SonarQube dashboard will not be able to display the "New code coverage" metrics, right? 

Thanks! 

G. Ann Campbell

unread,
Apr 25, 2018, 2:31:24 PM4/25/18
to Shruthi Berikai, SonarQube
Hi,

New Code metrics are a core feature of SonarQube. They will be there with or without Developer Edition.


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/abcbaad3-16af-4b5d-97d3-fd19ea722afb%40googlegroups.com.

shru...@yahoo.com

unread,
Apr 25, 2018, 2:42:38 PM4/25/18
to SonarQube
If new code coverage should be available without the Branch plugin, any idea why nothing is displayed in the Dashboard under Coverage on New code. Below image is what we are seeing for all projects.

Coverage xml report is generated but the report result is never displayed.


Thanks

G. Ann Campbell

unread,
Apr 25, 2018, 3:20:56 PM4/25/18
to Shruthi Berikai, SonarQube
Hi,

At the start of this thread I asked a whole bunch of questions of the OP. I can't hope to provide any answers without similar data from you.


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/4c346116-317c-4b6e-9719-e1616dd92dbc%40googlegroups.com.

shru...@yahoo.com

unread,
Apr 25, 2018, 3:30:07 PM4/25/18
to SonarQube
Sorry about that.. Here are the details. Let me know if you need any additional information. I understand the original thread was for Java. I do have another thread created a few weeks ago. Below details are copied from the other thread. If you prefer, we can continue the discussion in the other thread - https://groups.google.com/d/msg/sonarqube/xhtXMXE-fyE/Grfe3NO9CAAJ


SonarQube - 6.7.2 LTS
MSBuild Sonar Scanner - 4.1.1
C# plugin - 7.0.1.4822
MSBuild - 15
TFS 2017 Update 3
Visual Studio 2017 ASP.net MVC project

Issue - 
New code coverage metrics in SonarQube Dashboard never get updated. But the total lines etc do change. 

From the logs, I see the .trx, .coverage and .coveragexml files are generated. .Coveragexml file has data in it.

2018-04-17T14:42:42.4366806Z 09:42:42.434 INFO: Sensor C# Tests Coverage Report Import [csharp]
2018-04-17T14:42:42.4394427Z 09:42:42.434 INFO: Parsing the Visual Studio coverage XML report d:\b3_w\13\s\TestResults\tfsdevbuild.svc_AUSCMTFBD01_2018-04-17_09_42_13\In\AUSCMTFBD01\tfsdevbuild.svc_AUSCMTFBD01 2018-04-17 09_42_04.coveragexml
2018-04-17T14:42:42.5380448Z 09:42:42.528 INFO: Adding this code coverage report to the cache for later reuse: d:\b3_w\13\s\TestResults\tfsdevbuild.svc_AUSCMTFBD01_2018-04-17_09_42_13\In\AUSCMTFBD01\tfsdevbuild.svc_AUSCMTFBD01 2018-04-17 09_42_04.coveragexml


pasting part of the coveragexml it here - 
<?xml version="1.0" encoding="UTF-8" ?>
<results>
  <modules>
    <module name="tmhp.portal.accountactivation.dll" path="tmhp.portal.accountactivation.dll" id="6A45ABA8A8689A41BE1B11A43CD2586001000000" block_coverage="39.87" line_coverage="49.27" blocks_covered="2756" blocks_not_covered="4156" lines_covered="4649" lines_partially_covered="11" lines_not_covered="4776">
      <functions>
        <function id="9274" token="0x6000a08" name="OnAuthorization(System.Web.Mvc.AuthorizationContext)" namespace="TMHP.Portal.AccountActivation.Filters" type_name="AntiForgeryAttribute" block_coverage="0.00" line_coverage="0.00" blocks_covered="0" blocks_not_covered="1" lines_covered="0" lines_partially_covered="0" lines_not_covered="1">
          <ranges>
            <range source_id="78" covered="no" start_line="12" start_column="9" end_line="12" end_column="10" />
          </ranges>
        </function>
        <function id="10030" token="0x6000382" name="GetOwnershipInformationRequest()" namespace="TMHP.Portal.AccountActivation.LTCOwnershipService" type_name="GetOwnershipInformationRequest" block_coverage="0.00" line_coverage="0.00" blocks_covered="0" blocks_not_covered="2" lines_covered="0" lines_partially_covered="0" lines_not_covered="2">
          <ranges>
            <range source_id="3" covered="no" start_line="819" start_column="9" end_line="819" end_column="48" />
            <range source_id="3" covered="no" start_line="820" start_column="9" end_line="820" end_column="10" />
          </ranges>
        </function>
        <function id="10030" token="0x6000384" name="GetOwnershipInformationRequestBody()" namespace="TMHP.Portal.AccountActivation.LTCOwnershipService" type_name="GetOwnershipInformationRequestBody" block_coverage="0.00" line_coverage="0.00" blocks_covered="0" blocks_not_covered="2" lines_covered="0" lines_partially_covered="0" lines_not_covered="2">
          <ranges>
            <range source_id="3" covered="no" start_line="839" start_column="9" end_line="839" end_column="52" />
            <range source_id="3" covered="no" start_line="840" start_column="9" end_line="840" end_column="10" />
          </ranges>
        </function>
        <function id="10030" token="0x6000386" name="GetOwnershipInformationResponse()" namespace="TMHP.Portal.AccountActivation.LTCOwnershipService" type_name="GetOwnershipInformationResponse" block_coverage="0.00" line_coverage="0.00" blocks_covered="0" blocks_not_covered="2" lines_covered="0" lines_partially_covered="0" lines_not_covered="2">
          <ranges>
            <range source_id="3" covered="no" start_line="857" start_column="9" end_line="857" end_column="49" />
            <range source_id="3" covered="no" start_line="858" start_column="9" end_line="858" end_column="10" />
          </ranges>
        </function>
        <function id="10030" token="0x6000388" name="GetOwnershipInformationResponseBody()" namespace="TMHP.Portal.AccountActivation.LTCOwnershipService" type_name="GetOwnershipInformationResponseBody" block_coverage="0.00" line_coverage="0.00" blocks_covered="0" blocks_not_covered="2" lines_covered="0" lines_partially_covered="0" lines_not_covered="2">
          <ranges>
            <range source_id="3" covered="no" start_line="874" start_column="9" end_line="874" end_column="53" />
            <range source_id="3" covered="no" start_line="875" start_column="9" end_line="875" end_column="10" />
          </ranges>
        </function>
        <function id="24652" token="0x6000306" name="set_Phone(string)" namespace="TMHP.Portal.AccountActivation.LTCProviderService" type_name="ContractManager" block_coverage="100.00" line_coverage="100.00" blocks_covered="2" blocks_not_covered="0" lines_covered="3" lines_partially_covered="0" lines_not_covered="0">
  <ranges>
    <range source_id="20" covered="yes" start_line="595" start_column="17" end_line="595" end_column="41" />
    <range source_id="20" covered="yes" start_line="596" start_column="17" end_line="596" end_column="52" />
    <range source_id="20" covered="yes" start_line="597" start_column="13" end_line="597" end_column="14" />
  </ranges>
        </function>
        <source_files>
<source_file id="0" path="d:\b3_w\13\s\AccountActivation.UnitTest\Managers\RequestPinManagerTests.cs">
</source_file>
<source_file id="1" path="d:\b3_w\13\s\AccountActivation.UnitTest\Managers\AccountManagerTests.cs">
</source_file>
<source_file id="2" path="d:\b3_w\13\s\AccountActivation.UnitTest\Controllers\ProviderDetailsControllerUnitTests.cs">
</source_file>
<source_file id="3" path="d:\b3_w\13\s\AccountActivation.UnitTest\Controllers\AccountControllerTests.cs">
</source_file>
<source_file id="4" path="d:\b3_w\13\s\AccountActivation.UnitTest\Managers\ProviderDetailsManagerTests.cs">
</source_file>
<source_file id="5" path="d:\b3_w\13\s\AccountActivation.UnitTest\Managers\HomeManagerTests.cs">
</source_file>
<source_file id="6" path="d:\b3_w\13\s\AccountActivation.UnitTest\Controllers\RequestPinControllerUnitTests.cs">
</source_file>
<source_file id="7" path="d:\b3_w\13\s\AccountActivation.UnitTest\Controllers\HomeControllerTests.cs">
</source_file>
<source_file id="8" path="d:\b3_w\13\s\AccountActivation.UnitTest\Common\ControllerHelper.cs">
</source_file>
<source_file id="9" path="d:\b3_w\13\s\AccountActivation.UnitTest\Providers\ADServiceProviderTest.cs">
</source_file>
</source_files>
    </module>
  </modules>
</results>

G. Ann Campbell

unread,
Apr 25, 2018, 3:47:06 PM4/25/18
to SonarQube
Yes. Let's close this thread since a) the context turns out to be different, and b) you've already engaged with a colleague in another thread.


Ann
Reply all
Reply to author
Forward
0 new messages