Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Full Test Case Coverage entry
How-to guide

How to measure and improve Apex code coverage

Code coverage is not something you create. It is a number you measure by running tests, then improve by closing the gaps. Here is the loop for checking it and raising it in a sandbox or scratch org before you deploy.

By Dipojjal Chakrabarti · Founder & Editor, Salesforce DictionaryLast updated Jun 16, 2026

Code coverage is not something you create. It is a number you measure by running tests, then improve by closing the gaps. Here is the loop for checking it and raising it in a sandbox or scratch org before you deploy.

  1. Open the Developer Console

    From the gear menu in any org, choose Developer Console. This is the standard place to run Apex tests and read coverage without installing extra tooling.

  2. Run all tests

    Choose Test, then New Run, and add the test classes you want, or use Run All. Letting the full suite run gives an accurate org-wide figure rather than the cached estimate.

  3. Read the overall and per-class numbers

    Open the Tests tab and the Overall Code Coverage panel. Click any class to see its percentage and to highlight covered (blue) versus uncovered (red) lines in the source.

  4. Close the red lines with real tests

    For each uncovered line, write a test that drives that path, then add System.assert calls to verify the outcome. Re-run tests and confirm both the line and the assertion pass.

Key options
Overall Code Coverage panelremember

Shows the org-wide percentage that gates deployment; this is the number that must clear 75 percent.

Per-class line highlightingremember

Blue lines ran during tests, red lines did not; red is your exact list of gaps to fix.

Run All versus selected testsremember

Run All recalculates the full org figure, while a selected run only reflects the lines those tests touch.

Gotchas
  • Hitting 75 percent with no assertions passes the gate but verifies nothing; lead with System.assert.
  • Every trigger needs at least some coverage, or deployment fails no matter how high the overall number is.
  • The Calculate Your Organization's Code Coverage estimate reads low after editing test classes; run all tests for the real figure.
  • Deployment coverage is recomputed against the tests it runs and is never stored, so it can differ from your sandbox number.

See the full Test Case Coverage entry

Test Case Coverage includes the definition, worked example, deep dive, related terms, and a quiz.