Activity Forums Salesforce® Discussions Why we use Test.startTest() and Test.stopTest() in Test Class in Salesforce ?

  • Why we use Test.startTest() and Test.stopTest() in Test Class in Salesforce ?

    Posted by Kirandeep on February 18, 2020 at 3:44 pm

    Why we use Test.startTest() and Test.stopTest() in Test Class in Salesforce ?

    MOHIT replied 4 years, 9 months ago 2 Members · 1 Reply
  • 1 Reply
  • MOHIT

    Member
    February 19, 2020 at 6:23 am

    The startTest method marks the point in your test code when your test actually begins. Each test method is allowed to call this method only once. All of the code before this method should be used to initialize variables, populate data structures, and so on, allowing you to set up everything you need to run your test. Any code that executes after the call tostartTest and before stopTest is assigned a new set of governor limits.
    So, every time you use the test.start and test.stop in your test method, new set of governor limits are assigned to the code executing between them. If you don't use them in your testmethods there may be chances of your test methods over shooting the set governor limits.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos