-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
miss-match between apex code coverage log vs. code-formatter cobertura report #3030
Comments
Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support. |
Hello @sambit-diff 👋 None of the versions of Shared: Update to the latest version of Salesforce CLI (docs) and confirm that you're still seeing your issue. After updating, share the full output of |
Heya @sambit-diff -
from the "Apex Code Coverage" in the command output? I don't see any information related to coverage % there, just passing/failing/total/time once I lowered the coverage to <75% I got a warning, › Warning: Average test coverage across all Apex Classes and Triggers is 59%, at least 75% test coverage is required. within the generated files, I see matching results in your logs, and personal testing in in the within so from my side, I see matching code coverage values and was unable to reproduce your scenario. Am I missing something? |
If you could extract the test-coverage.log file from my attachment, and look for line no. 1964, the APEX class Then please search for this APEX class in In cobertura.xml file, the line
It's possible that you might not be able to replicate it, but in our case - we find this % Coverage miss-matched in almost all times. |
ok - I was able to reproduce this in dreamhouse-lwc by deleting the first two tests in sf project deploy start --source-dir force-app --test-level RunLocalTests --junit --coverage-formatters json-summary --coverage-formatters cobertura --results-dir take2 --verbose
.
.
.
Apex Code Coverage
Name % Covered Uncovered Lines
──────────────────── ───────── ───────────────────────
FileUtilities 53% 15,18,22,23,24,25,26,28 if you then look in <class name="FileUtilities" filename="no-map/FileUtilities" line-rate="0.68" branch-rate="1"> => 68% code coverage, vs our displayed 53% in the command output
"no-map/FileUtilities": {"lines":{"total":25,"covered":17,"skipped":0,"pct":68} => 68% code coverage, vs our displayed 53% in the command output |
This issue has been linked to a new work item: W-16822712 |
Hi @WillieRuemmele thanks for the update, and good to know you were able to reproduce the issue. Until we have this fixed, is it possible for you to confirm which % coverage is correct i.e., 1) apex code coverage in log, OR, 2) coverage-summary.json |
@sambit-diff - good question. so I had this in the deployment Apex Code Coverage
Name % Covered Uncovered Lines
──────────────────── ───────── ───────────────────────
FileUtilities 53% 15,18,22,23,24,25,26,28
and I was able to query for code coverage numbers which returned NUMLINESCOVERED NUMLINESUNCOVERED TESTMETHODNAME
─────────────── ───────────────── ──────────────────────────────────────
9 8 createFileFailsWhenIncorrectFilename
9 8 createFileFailsWhenIncorrectBase64Data
so then I had 9/(9+8) = 52.9. I was expecting the command output to be wrong, not the code formatters results. This also matches the coverage reported in the dev console, with some differences in rounding |
thank you @WillieRuemmele for your help and support Since coverage in command output is always less than code formatter results, we will now focus on improving code coverage based on command output. |
This issue has been fixed in CLI version 2.62.6 (October 16, 2024). |
This sounds like the same issue I reported here with inaccuracies in the deployment coverage report. forcedotcom/salesforcedx-vscode#5511 I made a Salesforce CLI plugin (https://github.com/mcarvin8/apex-code-coverage-transformer ) that could "work around" this by renumbering inaccurate lines. Like if an 100 line apex class is deployed, the coverage report may show 120 total lines and my plugin would have to renumber lines to make it work with SonarQube (not perfect but best I could come up with). Is this now fixed? My issue hasn't been updated in a bit and I haven't had time to create a support case for it. If this is fixed by a CLI build, I'd like to release a new version of my plugin which can remove the covered line adjustments I had to make. |
@jshackell-sfdc can you link the PR for the bugfix please? |
Summary
We are not using latest version of salesforce-cli, and the reason was already reported in past issue #2984. We haven't got a window from platform team to test / debug with latest updates. Meanwhile, we are still using salesforce-cli v2.51.6
In Azure pipelines, I am executing below SF command to validate a feature/* branch before merging to "develop" branch and deploying to non-prod sandboxes.
sf project deploy start --target-org dev --manifest source-dir-package.xml --pre-destructive-changes manifest/destructiveChanges/destructiveChanges.xml --ignore-warnings --test-level RunLocalTests --junit --coverage-formatters json-summary --coverage-formatters cobertura --dry-run --wait 60 --verbose --ignore-conflicts
Above command executes successfully, and generates 3 files:
We also could see Apex code coverage in the logs, I have attached the logs here for review.
Please could you compare % coverage from the section "Apex Code Coverage" in logs against the generated coverage-summary.json file - they don't match, unfortunately!
Especially, could you please check the APEX class AMSIntegrationCtrl.cls? This class file in feature/* branch has 345 lines in total, and I believe code statements excluding comments and empty lines, total lines for run coverage should be less than 345. In coverage-summary.json, this class shows 410 total lines. I am not sure how are we getting count larger than the actual file.
Steps To Reproduce
We find this issue on everytime we run the command i.e., apex code coverage summary in logs does not match with coverage-summary.json, with an exception i.e., when test coverage for an APEX class is NOT 100%.
Expected result
Code coverage summary should be same, After deploy, in next pipeline steps, we validate overall code coverage from coverage-summary.json should be greater than or equals to 85% for success.
Actual result
The details in coverage-summary.json is not correct. At least we know the total lines for an APEX class is not correct.
Additional information
System Information
Using Azure DevOps
code_coverage_debug.zip
The text was updated successfully, but these errors were encountered: