+ Start a Discussion

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.


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.