Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Salesforce QA / Tester
easy

What is Apex test coverage and why is 75% required?

Apex test coverage = percentage of Apex code lines exercised by unit tests.

Salesforce requires 75% test coverage before deploying Apex code to production. Reasons:

  • Quality gate — untested code is high-risk.
  • Bulk-safety — tests exercise bulk patterns.
  • Regression — tests catch breaking changes.

Coverage measurement:

  • Per Apex class: % of lines hit during test execution.
  • Triggers must have at least one test that touches them.
  • Test classes themselves don't count toward coverage (they're test code, not production).

Salesforce's coverage rules:

  • Production deploy: org-wide coverage 75%+; individual triggers 1%+ (i.e., all triggers must be touched).
  • Sandbox deploy: less strict.

Common coverage anti-patterns:

  • Coverage tests with no assertions — code lines exercised but behaviour unverified.
  • Tests that pass against any change — meaningless.
  • `@isTest(SeeAllData=true)` — tests depend on org data, fragile.

Quality vs quantity:

  • 75% with assertions — meaningful.
  • 75% without assertions — meaningless.
  • 85%+ with assertions — strong.
  • Test code lines counted — write good tests, not just lines.

Tools:

  • Apex Test Execution in Salesforce Setup.
  • VS Code Salesforce Extensions — coverage in IDE.
  • CI/CD — automated coverage check.
  • Apex Code Analyzer — quality + coverage analysis.

Beyond Apex:

  • LWC testing with Jest — separate tool, separate coverage.
  • Flow testing — limited tools.
  • Manual / UAT testing — coverage of features, not just code.

Senior QA insight: 75% is a gate, not a goal. Aim higher. And coverage without assertions is meaningless. Quality of tests matters more than the number.

The senior framing: tests are documentation of expected behavior. Each test asserts: "given X, when Y, then Z." Run tests; behaviour is documented.

Why this answer works

Foundational. The "gate not goal" insight and assertion-quality framing are mature.

Follow-ups to expect

Related dictionary terms