Monday, 16 February 2015

StartTest and stopTest Method


StartTest() 

Marks the point in your test code when your test actually begins. Use this method when you are testing governor limits.

public static Void startTest()

StopTest() 

Marks the point in your test code when your test ends. Use this method in conjunction with the startTest method.

public static Void stopTest()

NOTE :-

1) 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
2) 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. 
3) Any code that executes after the call to startTest and before stopTest is assigned a new set of governor limits.
4) The startTest method does not refresh the context of the test: it adds a context to your test. For example, if your class makes 98 SOQL queries before it calls startTest, and the first significant statement after startTest is a DML statement, the program can now make an additional 100 queries. Once stopTest is called, however, the program goes back into the original context, and can only make 2 additional SOQL queries before reaching the limit of 100
5) All asynchronous calls made after the startTest method are collected by the system. When stopTest is executed, all asynchronous processes are run synchronously