Apex Test Class Best Practices in Salesforce | how do you write a test class for Apex class in Salesforce

There are many points keep in mind whenever we write test class:-


To know more details about Test Class Best Practices, Click Here.

  • Use @isTest at the Top for all the test classes.
  • Avoid Using Hard Coding Ids anywhere in test Class
  • Use System.runAs() method to test the functionality in user Context
  • Check debug log. Make sure right tick must appear when you run your test class. Else check for errors.
  • Use Test.startTest() and Test.stopTest() statement to increase Governor Limits of your test code.
  • Use System.assertEquals() to see if your code has the expected outcomes
  • Test in bulk: Test to see if your code can run on 200 records at once. This is the maximum number of records that can be evaluated in a single trigger by Salesforce.
  • To deploy to production at-least 75% code coverage is required. and also the main functionality has been covered. If possible increase code coverage up to 95%.
  • We should not focus on the percentage of code coverage, we should make sure that every use case should covered including positive, negative,bulk and single record.
  • Test method should static and no void return type.
  • @Testvisible annotation to make visible private methods inside test classes.
  • Test method cannot be used to test web-service call out . Please use call out mock .
  • You can't send email from test method.
  • Use the @testSetup method to insert the common test data into the Test class that will flow all over the test class.
  • Do not put (seeAllData = true) in test class otherwise, use it for exceptional cases.


To know more live demo source code in Salesforce lightning, Trigger, Visualforce & LWC, Use this link..



Apex Test Class Best Practices in Salesforce | how do you write a test class for Apex class in Salesforce Apex Test Class Best Practices in Salesforce | how do you write a test class for Apex class in Salesforce Reviewed by Admin on 3:03 AM Rating: 5

9 comments:

  1. your post is amazing and I really loved reading your post.
    Great Thanks for sharing awesome info. It was very well authored and easy to understand.
    I have a information about fake ID card. Idsbuddy is 𝐛𝐞𝐬𝐭 𝐟𝐚𝐤𝐞 𝐢𝐝 𝐰𝐞𝐛𝐬𝐢𝐭𝐞𝐬. You can learn more information about fake id from this website. you can check best fake id websites

    ReplyDelete
  2. hello friends this site is the very popular and useful.matka

    ReplyDelete
  3. A proper kindly of research is very necessary before selecting the broker also we should keep in mind that reviews should not be trusted blindly, there should be someone who is from our friend circle who have worked with that broker bitforex

    ReplyDelete

header banner -- www.w3web.net



Powered by Blogger.