Activity Forums Salesforce® Discussions What are the best practices while writing Test Classes in Salesforce?

  • Shubham

    Member
    January 28, 2020 at 2:42 pm

    Hi Ratnesh,

    Some of the best practices for writing test classes are:-

    1-Try not just covering 75% of the code, but as much coverage as possible

    2-If possible Don’t use seeAllData=true, Create your Own Test Data.

    3-Always use @testSetup method dedicated to create test records for that class. This is newly added annotation and very powerful. Any record created in this method will be available to all test methods of that class.

    4-Use Test.startTest() to reset Governor limits in Test methods

    5-Use Test.isRunningTest() in your code to identify that context of class is Test or not.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos