Code Coverage showing null for SAP Hyrbis Project

We are using the SonarQube to analyse our SAP Hybris code. We have successfully generated Jacoco XMl reports but while importing it in sonarqube it gives 0% code coverage.

I have mentioned all the versions details which we are using:
Sonarqube : Developer Edition v9.9.1
Jacoco: 0.8.9 (Download Jacoco CLI and Agent on Server)
Java: 17.0.7

We have tried below steps:

Step 1: Download jacocoAgent.jar file
wget https://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.8.9/org.jacoco.agent-0.8.9-runtime.jar -O jacocoAgent.jar

Step 2: Run Ant Alltests

ant alltests \
      -Dtestclasses.extensions=ext1,ext2,ext3,ext4 \
      -Dtestclasses.reportdir=/tmp/alltests \
      -Dstandalone.javaoptions="-Djava.locale.providers=COMPAT,CLDR -javaagent:/tmp/jacocoAgent.jar=destfile=/tmp/jacocoAlltests.exec"
 
Step 3: Run Ant Webtests
ant allwebtests \
      -Dtestclasses.extensions=ext1,ext2,ext3,ext4 \
      -Dtestclasses.reportdir=/tmp/allwebtests \
      -Dstandalone.javaoptions="-Djava.locale.providers=COMPAT,CLDR -javaagent:/tmp/jacocoAgent.jar=destfile=/tmp/jacocoAllwebtests.exec"

Step 4: Download jacocoCli.jar file
wget https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/0.8.6/org.jacoco.cli-0.8.6-nodeps.jar -O jacocoCli.jar

cd ${HYBRIS_HOME}/hybris/bin/platform

Step 5: Generate jacocXMl Report file

java -jar /tmp/jacocoCli.jar report \
       /tmp/jacocoAlltests.exec \
       /tmp/jacocoAllwebtests.exec \
       --classfiles ${HYBRIS_HOME}/hybris/bin/modules/custom/ext1 \
       --classfiles ${HYBRIS_HOME}/hybris/bin/modules/custom/ext2 \
       --classfiles ${HYBRIS_HOME}/hybris/bin/modules/custom/ext3 \
       --classfiles ${HYBRIS_HOME}/hybris/bin/modules
       --xml /tmp/jacocoTestReport.xml

Step 6: Run SonarQube analysis

ant sonarcheck
      -Dsonar.host.url= \
      -Dsonar.login= \
      -Dsonar.projectKey= \
      -Dsonar.projectName="Custom Extensions" \
      -Dsonar.projectVersion=1.0.0-SNAPSHOT \
      -Dsonar.java.source=11 \
      -Dsonar.extensions=ext1,ext2,ext3,ext4 \
      -Dsonar.junit.reportPaths=/tmp/alltests,/tmp/allwebtests \
      -Dsonar.test.exclusions= \
      -Dsonar.coverage.jacoco.xmlReportPaths=/tmp/jacocoTestReport.xml

I would request to help us to understand what we are missing.

What do the logs say about the import of code coverage?

https://community.sonarsource.com/t/how-to-find-logs-about-importing-code-coverage/73317/3

@Colin Thanks for you response.

Now I’m able to see code coverage report when running sonarqube analysis for whole branch. But still I’m facing issue while running sonarqube analysis for Pull Request.
So can you please give me list of steps in sequence? I’m using Jenkins pipeline for CI/CD.

Below are the list of steps configured in Jenkins Pipeline.

  1. Checkout Base Branch (Target Branch)
  2. Run Ant build
  3. Run test cases and generate jacoco.xml report
  4. Run Sonarqube Analysis
  5. Check Quality Gate.

Below are the sonarqube properties:

-Dsonar.projectName=<project name> \
-Dsonar.java.binaries=. \
-Dsonar.projectKey=<project key> \
-Dsonar.projectVersion=1.1  \
-Dsonar.projectDescription=<project description> \
-Dsonar.projectBaseDir=<custom directory path> \
-Dsonar.sourceEncoding=UTF-8 \
-Dsonar.pullrequest.key=<Pull Request ID> \
-Dsonar.pullrequest.branch=<Feature Branch> \
-Dsonar.pullrequest.base=<Base Branch> \
-Dsonar.coverage.jacoco.xmlReportPaths=jacoco.xml

please let me know if anything is incorrect in above steps.

Hey there.

Everything seems in order with the steps you’ve mentioned. My question is still the same if it’s not working for your pull request – what do the logs say? And what do you see in SonarQube that means to you coverage isn’t being processed? Feel free to share a screenshot here.

@Colin I have attached image for sonarqube dashboard. As It shows bugs, code smells but not coverage. I’m not sure whether its correct or not.

As per my understanding for PR analysis, code coverage only shows if there is any test cases for new code. Can you please correct me if I’m wrong ?

That’s true – and, if coverage information is being imported at all, you should see some figure for the “Estimated after merge” figure.

So, for a third time, what do the logs say? :smiley:

That’s true – and, if coverage information is being imported at all, you should see some figure for the “Estimated after merge” figure.

My main concern regarding PR code coverage is resolved from your answer.

Also I have added -Dsonar.verbose=true property in Sonar Scanner, it shows debug info while running Jenkins Pipeline but it didn’t shows any errors.