Apex Test Coverage Generated in CI but Not Reflected in SonarCloud Dashboard

We are using SonarCloud (SaaS) to analyze Salesforce Apex code. As part of our CI pipeline, Apex tests are executed successfully and code coverage is generated correctly during the Salesforce test run.

However, the same Apex test coverage is not being reflected in the SonarCloud dashboard after the analysis completes. The SonarCloud analysis finishes without errors, but the reported coverage remains 0% / outdated / missing for Apex files.

Hi,

Welcome to the community!

How are you trying to import your coverage into the analysis? This doesn’t happen automatically, you need to explicitly pass the coverage report in using the sonar.apex.coverage.reportPath parameter.

 
HTH,
Ann

We are using SonarCloud (SaaS) for Salesforce (Apex). Our Apex test coverage is correctly generated during CI / Salesforce test run, however the same coverage is not reflected in SonarCloud dashboard

  • CI system used - Gitlab

  • Languages of the repository : Apex Code

  • Coverage mismatch snips
    Coverage reflected in coverage json report.

    Coverage in sonar cloud report

Hi,

In sonar stages, we have 2 sub stages,viz run_apex_tests and sonarcloud check, refer below snip.

coverage report is generated in the run_apex_tests stage and shared via artifacts to sonarcloud-check stage

artifacts:
paths:

  • test-results/

The coverage path is explicitly configured in sonar.properties as sonar.apex.coverage.reportPath=./test-results/test-result-codecoverage.json

Hi,

Can you share your analysis log?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Thx,
Ann

sonar-scanner-analysis.log.txt (12.4 KB)

We’ve shared the full SonarScanner analysis log from our GitLab pipeline. Please let us know if you need anything else.

Hi,

I assume you and the OP are colleagues? :slight_smile:

Thanks for the log. It shows the problem:

06:20:56.909 ERROR SFDX coverage report not found: './test-results/test-result-codecoverage.json'

So now, where does this file sit in relation to where analysis is kicked off from?

 
Ann