just right now, while deploying some code from Sandbox environment to the Production one, I was noticing something strange within a test class that should have the aim to test a Batch class. I notice that the executeBatch()
call is not enclosed within Test.startTest()
and Test.stopTest()
methods.
Now, as per documentation ( https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_batch_2.htm), these methods should be used so that the asynchronous call (like my executeBatch()
) are collected and executed synchronously after the Test.stopTest()
call.
However, without using these two methods, my test runs correctly.
Now I wonder: is using start/stopTest() an "optional" best practice?
There's something other I'm missing?