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
sudhakar reddy 13sudhakar reddy 13 

Define Test.startTest() and Test.stopTest() and its usage in the test class.

Amit Chaudhary 8Amit Chaudhary 8
Please check below post. I hope that will help you
http://amitsalesforce.blogspot.in/2015/06/salesforce-testing-best-practice.html
http://amitsalesforce.blogspot.in/2015/06/best-practice-for-test-classes-sample.html

Please check below blog for more detail
http://amitsalesforce.blogspot.in/2015/02/starttest-and-stoptest-method.html

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

Please let us know if this will help you

Thanks
Amit Chaudhary

 
Ramk123Ramk123
Thanks Amit..It's really helpfull
Amit Chaudhary 8Amit Chaudhary 8
Please mark the best Answer if that helped you. So that some one have same issue that post can help other