# Coverage on new code doesn't work

**URL:** <https://community.sonarsource.com/t/coverage-on-new-code-doesnt-work/21484>\
**Category:** SonarQube Server / Community Build\
**Tags:** coverage\
**Created:** [March 11, 2020, 5:02pm UTC](https://community.sonarsource.com/t/coverage-on-new-code-doesnt-work/21484 "2020-03-11T17:02:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carlos\_Rojas](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/carlos_rojas/32/10075_2.png) [@Carlos\_Rojas](https://community.sonarsource.com/u/Carlos_Rojas)\
**Post date:** [March 11, 2020, 5:02pm UTC](https://community.sonarsource.com/t/coverage-on-new-code-doesnt-work/21484/1 "2020-03-11T17:02:51Z")

</div>

Versions used: **Version** 7.8.0.26217 Developer Edition

Error observed: Coverage on new code is considering the whole file, not new code only. I have a java file that its coverage is %0 on the base line,I am doing unit test to all my new changes (with a 100% coverage on all new code), however sonar is getting the coverage of all code, breaking the my quality gate. I am running a Pull Request Analisys.

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/2X/7/7364cb2f5fd3eea80571edaa77e83f8dfa6a8ba0.png)

Image is showing the coverage on new code (dispite I covered ALL my new code) that I got running a Pull Request Analysis, on base line coverage is 0%

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [March 11, 2020, 6:15pm UTC](https://community.sonarsource.com/t/coverage-on-new-code-doesnt-work/21484/2 "2020-03-11T18:15:08Z")

</div>

Hi,

Welcome to the community!

I’m glad you included a screenshot because the yellow highlight is showing me that SonarQube appears to be considering all the lines in your file as new/changed. We’ve seen this happen when you (or perhaps your automation) change/standardize, for instance spacing or line endings in the file. Could that have happened?

And BTW, this is “new” as reported by your SCM. We rely on the data it supplies.

&nbsp;  
HTH,  
Ann

---

<div class="post-metadata">

**Author:** ![Carlos\_Rojas](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/carlos_rojas/32/10075_2.png) [@Carlos\_Rojas](https://community.sonarsource.com/u/Carlos_Rojas)\
**Post date:** [March 12, 2020, 9:56pm UTC](https://community.sonarsource.com/t/coverage-on-new-code-doesnt-work/21484/3 "2020-03-12T21:56:14Z")

</div>

Hello G Ann,

The code isn,'t new since the first analysis, I mean, I ran an analyse using the main branch to set the base line, afterward, I ran the Pull Request Analysis.

In the image I´m attaching you can see my pull request from Azure DevOps (the same code I shown in the last post), the red square mark the change, and the blue one confirm that there is no changes in the next lines.

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/2X/d/d8a13bdbc45cb348f924e2dfd83594f2f7c18370.png)

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [March 13, 2020, 12:32pm UTC](https://community.sonarsource.com/t/coverage-on-new-code-doesnt-work/21484/4 "2020-03-13T12:32:35Z")

</div>

Hi,

Your SCM is telling SonarQube that the lines are new. When you click on it in the margin, what date do you see? E.G.  
 ![Selection_949](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/2X/5/523e73ee5d0e46dbae84dd95ac159922e6f59aad.jpeg)

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Carlos\_Rojas](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/carlos_rojas/32/10075_2.png) [@Carlos\_Rojas](https://community.sonarsource.com/u/Carlos_Rojas)\
**Post date:** [March 16, 2020, 11:38pm UTC](https://community.sonarsource.com/t/coverage-on-new-code-doesnt-work/21484/5 "2020-03-16T23:38:24Z")

</div>

I marked in yellow the analysis and code date.

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/2X/9/9247e0f973285f5cda3b54ea3d725040685ec87e.png)

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [March 17, 2020, 7:12pm UTC](https://community.sonarsource.com/t/coverage-on-new-code-doesnt-work/21484/6 "2020-03-17T19:12:25Z")

</div>

Hi,

Thanks for the screenshot!

Now could you also check your front page and send a screenshot of when your New Code period started? In 8.2 it looks like this:

![Selection_960](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/2X/3/331faae716667a1200273751776be13a93c6b1cc.jpeg)

In 7.8 (you really should upgrade, you know) you’ll find it at the top of the yellow column on the project homepage.

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Carlos\_Rojas](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/carlos_rojas/32/10075_2.png) [@Carlos\_Rojas](https://community.sonarsource.com/u/Carlos_Rojas)\
**Post date:** [March 17, 2020, 7:32pm UTC](https://community.sonarsource.com/t/coverage-on-new-code-doesnt-work/21484/7 "2020-03-17T19:32:25Z")

</div>

![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/2X/3/333f8e33dd501e9e4c0c2240eb86d352a7da607c.png)

---

<div class="post-metadata">

**Author:** ![dmeneses](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/dmeneses/32/2933_2.png) [@dmeneses](https://community.sonarsource.com/u/dmeneses)\
**Post date:** [March 17, 2020, 8:32pm UTC](https://community.sonarsource.com/t/coverage-on-new-code-doesnt-work/21484/9 "2020-03-17T20:32:53Z")

</div>

Next thing to check is if the scanner is able to read the information from git. More specifically, what are the changed between the P/R and it’s target branch.  
When scanning the P/R, could you please provide the logs of the scanner with debug enabled?

---

<div class="post-metadata">

**Author:** ![Carlos\_Rojas](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/carlos_rojas/32/10075_2.png) [@Carlos\_Rojas](https://community.sonarsource.com/u/Carlos_Rojas)\
**Post date:** [March 18, 2020, 2:17pm UTC](https://community.sonarsource.com/t/coverage-on-new-code-doesnt-work/21484/10 "2020-03-18T14:17:03Z")

</div>

How I set debug enabled?

---

<div class="post-metadata">

**Author:** ![dmeneses](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/dmeneses/32/2933_2.png) [@dmeneses](https://community.sonarsource.com/u/dmeneses)\
**Post date:** [June 1, 2020, 8:08pm UTC](https://community.sonarsource.com/t/coverage-on-new-code-doesnt-work/21484/11 "2020-06-01T20:08:55Z")

</div>

Sorry, I missed your last reply.  
You can pass `-X` or `-Dsonar.verbose=true` to the scanner.
