No backspacing blog - @Xi Xiao

Testing on lightning platform

Testing on lightning platform

Testing is a fascinating topic for Salesforce developers. For one obvious reason, the platform demands 75% code coverage testing. For another, Writing good testing reflects the developer’s coding experience and the flexibility of OO design.

I just wanna highlight several iportant points of Apex testing, so I can come back to review them when I forget :).

  1. System.StubProvider is a powerful stubbing method. I (you too) should learn and use it in my testing.
  2. DML is usually unnecessary. Ask myself questions:
    • Am I testing any DML related code (Triggers, Process Builders, etc.)?
    • Do I have any need to insert these records?
    • Can my code be written to have these records retrieved via a mockable method?
  3. Record in memory allows to set a bogus Id.
  4. Test visible for variable and method. Use it well to make magic, refer to Dan Appleman’s Advanced Apex Programming book.

Study Resource