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

Why we are using test.start and test stop test methods in test class to batch apex ?
Hi Experts,
i have little confuse ,Why we are using test.start and test stop test methods in test class to batch apex ? Any one can demonstrate on this . pls don't paste the link.
Regards,
Chanti
i have little confuse ,Why we are using test.start and test stop test methods in test class to batch apex ? Any one can demonstrate on this . pls don't paste the link.
Regards,
Chanti
We don't use Test.StartTest and Test.stopTest for batch apex only. We can use in any test class.
The purpose of test.StartTest and Test.StopTest is to reset salesforce Governance limit. It is best practise to create dummy data for test classes and it requires DMLS and SOQL.
So while executing actual apex classes to get full set of governance limit we use Test.startTest and test.stopTest and execute actual logic in between Test.starTest and Test.stopTest.
Best Regards,
Amit Ghadage.
So, every time you use the test.start and test.stop in your test method, new set of governor limits are assigned to the code executing between them. If you don't use them in your testmethods there may be chances of your test methods over shooting the set governor limits.
More details can be found in this salesforce documentation for the above.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_tools_start_stop_test.htm
StartTest stopTest resetting the governor limits, is an additional advantage you get. The primary goal of start and stopTest is execution of async code. As Async method query limits ideally should not be counted with your synchronous SQL queries in the test method, hence the code (SQL queries) between startTest and stopTest gets their own limits.
Hope this clarifies your doubts. If you have further questions, feel free to ask. Otherwise mark this as green. :-P
Cheers, Dev
For example if you call queueable apex from a trigger then the trigger passes records in a batch of 200 records to the queueable class and the limits resets everytime it calls the queueable implemeted class because it is an async process (correct me if I am wrong here). If yes, does the same thing happen inside the test block ?
Thanks in advance.