Why there is difference in codecoverage

Hello Team,

I am working on a static code analysis for Salesforce.
I am using self-hosted SonarQube enterprise 8.3 and triggering the analysis from Azure DevOps.

I running “sfdx force:apex:test:run --targetusername $username --resultformat json --outputdir . --codecoverage --testlevel RunLocalTests” to generate the code coverage from salesforce and then importing “test-result-codecoverage.json” file into sonarqube.
sonar.apex.coverage.reportPath=test-result-codecoverage.json
I see there is a huge difference in code-coverage between salesforce and Sonarqube.
Coming to the root cause I found that the JSON that salesforce CLI is providing has different data than what I see on salesforce UI.

Please suggest how do I resolve this?, how do I match code-coverage on sonarqube and salesforce?

Thanks,
Abhishek

Hi Abhishek,

I guess you meant “than what I see on the SonarQube UI”?

I suspect this is about executable lines. This blog post should help.

 
Ann

1 Like

Hello @Alexandre_Gigleux, I am using this command to get the code coverage report, and importing it into SonarQube, But I see there is a difference in Salesforce and SonarQube code-coverage.
Coming to the root cause I found that there is a difference in test-result-codecoverage.json and salesforce U data, because of which I find that there is a difference on sonarqube.

Please suggest how do I resolve this? how do I match sonarqube with salesforce?

Thanks,
Abhishek

For the record, I consolidated here a nearly identical post that had been added to the Apex coverage guide .

1 Like