Apex Code Coverage Updates for apex:test:run and apex:test:report commands
See original GitHub issuePosting this draft of planned changes for community input -
When you run the force:apex:test:run or force:apex:test:report command, you see details about the updated code coverage in your Org. The information displayed can be confusing - some examples of why:
- Dev Console displays the Overall Org-wide coverage along with the percent covered for each Apex class
- The CLI & VS Code, provide a granular view of the test - showing you each method and class being covered by the test you ran (not the whole org). Furthermore, the coverage percentage for specific classes in the CLI & VS Code does not always match the respective number in the Developer Console. We also calculate an aggregate “Test Run Coverage” number that has no relationship to the Overall Org-wide coverage.
We’re clarifying the code coverage info so you get consistent info no matter where you work. We’re also simplifying so you have less info overall to process.
Here’s our draft of the planned changes to the human readable format. It contains 3 sections:
SECTION 1
This shows a summary of the coverage by class:
- Classes - The name of the class in the Org
- Percent - Percentage of lines covered by tests for this class. ApexCodeCoverageAggregate.Coverage (https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_apexcodecoverageaggregate.htm)
- Uncovered lines - Lines of code in the class that aren’t covered by a test. We will show a max of 5 and add“…“ after the 5th line number if there’s more.
SECTION 2
The table provides a summary of this test run. (or the last run executed if using force:apex:test:report). Couple things to call out:
- Org Wide Coverage -
ApexOrgWideCoverage.PercentCovered
. This is the Overall Apex Coverage in your Org after this test has run. This is seen as the “Overall” code coverage percentage in Dev Console. - We removed 7 values from table to streamline the view. Goal is to reduce the clutter and give you what you need. (Leave a comment and let us know if there’s anything you’ll miss!)
SECTION 3
This gives you a breakdown of all the elements in this test. The “Class Coverage” is the percentage of the class covered by this test. This value is from ApexCodeCoverage.Coverage
. We’re adding this value to give you insight into how much work each test is doing.
EXAMPLES: Here’s how these sections map to some example commands:
sfdx force:apex:test:run —classnames MyTest —codecoverage —resultformat human
- Shows sections 1 & 2
sfdx force:apex:test:run —classnames MyTest —codecoverage --detailedcoverage —resultformat human
- Shows sections 1, 2 & 3
- Note:
—detailedcoverage
would be a new flag. Name is not finalized.
sfdx force:apex:test:report —i 707400000e4G -r human
- Shows sections 1, 2 & 3
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:7 (5 by maintainers)
Top GitHub Comments
Hi @jefersonchaves - It’s the same area. With the update in Spring '20, we were attempting to have consistent info on Code Coverage no matter where you look. However, we’ve found that it doesn’t cover all cases because of the way the current Apex CLI commands work. The spec here is to rework this area fully and close all gaps. (and do some clean-up)
This has been delivered. Check out the commands or this recent blog.