You need to sign in to do that
Don't have an account?

Test.Starttest() question
Hi,
I am just wondering if someone can explain when I am supposed to use Test.StartTest() and Test.StopTest() ?
If I have a testmethod already, and the @istest notation, are the aforementioned methods necessary to perform a test? Can I run the test without them? When should I be starting-stopping?
Thanks!!
High level, lets say that before calling startTest, you should create all the information required for your test.
Then you call startTest and the limits get reset (Number of queries, dmls, etc.), so you can Test if your code will be able to handle batches, for example, etc.
All Answers
High level, lets say that before calling startTest, you should create all the information required for your test.
Then you call startTest and the limits get reset (Number of queries, dmls, etc.), so you can Test if your code will be able to handle batches, for example, etc.
From the point of view of "Governor Limits".
to provide, the number of DML, SOQL are not beyond the Governor Limits.
Useful References :
http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_best_practices.htm
http://blog.tquila.com/2011/11/17/salesforce-testing-best-practices/
http://salesforceworld.blogspot.in/2012/03/unit-testing-in-salesforce.html
Aha I see.
Thanks to you both!