Activity Forums Salesforce® Discussions Why do we write startTest() and stopTest() methods in Test Class in Salesforce?

  • Sanjana

    Member
    July 5, 2018 at 6:26 am

    Hello Shradha

    Test.startTest is used to mark the point in your test code when your test actually begins. Each test method is allowed to call this method only once. After you call this method, you get a fresh set of governor limits for the remainder of the test until you call Test.stopTest.

    Test.stopTest is used to marks the point in your test code when your test ends. Each test method is allowed to call this method only once. After calling this method, any post assertions are done in the original context.

  • shariq

    Member
    September 19, 2018 at 1:03 am

    Hi,

    There are two points -

    • To renew governer limits of salesforce.
    • To synchronize the run of batches and scheduler.

    Hope this helps.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos