Q:

SonarQube - unity tests code coverage on new code not working

I am trying to do Sonar analysis with the unit tests code coverage on new code. When I do code coverage analysis with cobertura and do Sonar analysis the overall code coverage of the code is displayed correctly, however the code coverage of new code is not displayed. 
Settings:

scm = Git
sonar.scm.disabled = false

I did following

checked out earlier version of source code
set Sonar project version to 1.0
created Cobertura report (xml file)
executed analysis and checked that the analysis was uploaded, the overal code coverage by unit tests was displayed correctly
checked out latest version of source code
set Sonar project version to 2.0
executed analysis and checked that the analysis was uploaded, the overal code coverage by unit tests was displayed correctly

The overall code coverage of the code by unit tests got increased as I have implemented some unit tests on a code that was changed. The On New Code item in the widget however stays hidden and the code coverage of new code is not displayed.
Does any of you have any tips that could bring more light to this?
Thank you all.

A:

You're observing this behaviour because Coverage on new code currently identifies new code based on the date of the previous analysis (and not the commit date of the code previously analyzed), see SONAR-7085 .
For your scenario to work you have to force a past date for the analysis of the old code, using -Dsonar.projectDate. Good article on this right here: Sonar Time Machine : replaying the past .

