Unit Tests for Apex

How to write tests and attain code coverage for the Lightning Platform.

Points to note:

  • Test methods take no arguments.
  • The visibility of a test method doesn’t matter, so declaring a test method as public or private doesn’t make a difference as the testing framework is always able to access test methods. For this reason, the access modifiers are omitted in the syntax.
  • Test methods must be defined in test classes, which are classes annotated with isTest.
  • Test classes can be either private or public. If you’re using a test class for unit testing only, declare it as private. Public test classes are typically used for test data factory classes.

Learn more here: