Activity Forums Salesforce Questions and Answers 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 ?

  • Kirandeep

    Member
    February 18, 2020 at 3:44 pm

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

  • 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.

Viewing 1 - 2 of 2 posts

Log in to reply.

Original Post
0 of 0 posts June 2018
Now