question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Apex Code Coverage Updates for apex:test:run and apex:test:report commands

See original GitHub issue

Posting 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 image

This shows a summary of the coverage by class:

SECTION 2 image

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 image

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

Related Github issues: #1630 & #1447

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
smaddox-sfcommented, Jun 4, 2020

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)

0reactions
smaddox-sfcommented, Apr 13, 2021

This has been delivered. Check out the commands or this recent blog.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apex Code Coverage Updates in the CLI
Here's a mock-up of the streamlined output when running the force:apex:test:run or force:apex:test:report commands: Percentages for class  ...
Read more >
Clearer Apex Commands : - Salesforce Reader
Our updates will bring you accurate code coverage numbers, cleaned up results, and a new flag to see detailed coverage information. We'll also ......
Read more >
What does the SFDX_IMPROVED_CODE_COVERAGE ...
We improved the force:apex:test:run and force:apex:test:report commands to provide more accurate code coverage results.
Read more >
Monitoring Your Apex Code Coverage Using Salesforce DX ...
Finally, run your tests with code coverage using the following command: sfdx force:apex:test:run --codecoverage --resultformat human.
Read more >
New Delhi Salesforce News and Updates: Week #50
... for the sfdx force:apex:test:run and sfdx force:apex:test:report commands! Our updates will bring you accurate code coverage numbers, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found