1. The Apex testing framework enables you to write and execute tests for your Apex classes and triggers on the Lightning Platform.
  2. Apex Unit tests ensure high quality for your Apex code and let you meet the requirements for deploying Apex.
  3. Apex code can only be written in a Sandbox environment or a Developer org, not in Production.
  4. Apex code can be deployed to a production org from a sandbox. Also, app developers can distribute Apex code to Customers from their Developer orgs by uploading packages to the Lightning AppExchange.
  5. In addition to being critical for quality assurance, Apex unit tests are also requirements for deploying and distributing Apex.

Benefits of Apex Unit Tests

  1. Ensuring that your Apex classes and triggers work as expected.
  2. Having a Suite of regression tests that can be rerun every time classes and triggers are updated to ensure that future updates you make to your app don’t break existing functionality.
  3. Meeting the code coverage requirements for deploying Apex to production or distributing Apex to Customers via packages.
  4. High-quality apps are delivered to the production org, which makes production users more productive.
  5. High-quality apps delivered to package subscribers, which increase your customers trust.

Code Coverage Requirement for Deployment

  1. Before you can deploy your code or package it for the Lightning Platform AppExchange, at least 75% of Apex code must be covered by tests, and all those tests must pass.
  2. In addition, each trigger must have some coverage. Even though Code coverage is a requirement for deployment, don’t write tests only to meet this requirement.
  3. Make sure to test the common use cases in your app, including positive and negative test cases, and bulk and single-recording processing.

Important to Remember

  1. Calls to System.debug are not counted as part of Apex code coverage.