function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KIRONKUMARKKIRONKUMARK 

What is Test.startTest() and Test.stopTest() methods?

What is Test.startTest() and Test.stopTest() methods?

 

 

What is the importance of these methods in test Class?

 

What will happen internally if these methods are used.

bob_buzzardbob_buzzard

These are used to allow your setup/confirmation code to run in a different context to the actual test so that you have a correct view of how your code performs against limits.  

 

For example, if your code required complex setup, you might use a number of SOQL and DML calls.  If your test ran in the same context, you could break governor limits due to the impact of the setup code.  The code in between start/stop test runs with its own set of limits etc.

Mohammad AnisMohammad Anis
Hi Kiron,

You can get the difference between the Test.startTest() and Test.stopTest() methods at the below link as :

Link : https://success.salesforce.com/answers?id=90630000000hr9tAAA

Please mark this as best answer if your query is resolved.

Regards,
Anis