Code coverage not displaying on PR analysis

java

(Alwyn Davis) #1

Hi,

I’m having trouble getting pull request code coverage analysis to work on particular Maven project. The long-lived branch will display test coverage analysis, but the pull requests will not.

From within the module directory, I generate the exec files:
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent test -DskipTests=false -Dgroups=small

And confirmed that the files are generated.

I then run the sonar analysis step:
mvn sonar:sonar -Dsonar.projectKey=<project-key> -Dsonar.verbose=true -Dsonar.host.url=https://sonarcloud.io -Dsonar.pullrequest.branch=alwyn-test-pr-2 -Dsonar.pullrequest.base=release-alwyn -Dsonar.pullrequest.key=1602 -Dsonar.login=<key>

However, I’ve tried the same steps against a test repository and am able to get PR test coverage to display.

The only difference I’ve been able to find between the working and non-working repos is that the non-working repo outputs:
[WARNING] File '/Development/app/java/common/src/main/java/com/blah/util/FakeUtil.java' was detected as changed but without having changed lines

The above warning seems incorrect given that this a new file that I’ve added in the PR.


(Duarte Meneses) #3

Hi,
The warning you posted seems to indicate that there is a problem detecting lines that were changed, in the scanner side.
Please check that:

  • The git branches are referencing the right commits when running the scanner (alwyn-test-pr-2 and release-alwyn)
  • All changes are committed in git
  • You don’t have a shallow clone

(Alwyn Davis) #4

Hi Duarte,

Yep, I’m definitely using the right PR branch and target branch:

git checkout alwyn-test-pr-2
Switched to branch 'alwyn-test-pr-2'
Your branch is up to date with 'origin/alwyn-test-pr-2'.
git checkout release-alwyn
Switched to branch 'release-alwyn'
Your branch is up to date with 'origin/release-alwyn'.

I’m also running the scanner locally (i.e. directly on the files I’m changing) and am not using a shallow clone.


(Duarte Meneses) #7

Hi,

Recently we found this bug: https://jira.sonarsource.com/browse/SONARSCGIT-35
Essentially the detection of new lines might not work if the root directory of the project doesn’t match the root of the git repository.
Is it the case in your project?


(Alwyn Davis) #8

Hi Duarte,

Thanks for highlighting that issue; it looks like that was the cause!

I copied our code into a new repository with the code to analyse in the root folder. Ran a base analysis on “master” and then on a “test” branch targeting “master”; the SonarCloud results then showed both changed lines and missing test coverage:

(I think I’ve replicated the steps from Lines to cover on new code is 0 in PR and for branches)

I can’t see anyway to workaround this for now, so I guess we’ll just have to wait for the fix to be released!

Thanks.