Batch class execute() method not covered by test class

Batch class execute() method not covered by test class

Please check the following if the Batch class execute() method is not getting covered by test class 
1. Remember that the execute method will be called only once. 

2. If you have chained batch classes, create separate methods for each and every batch class.

3. Make sure the start method fetches the required to process in execute method.

4. Execute the batch class within Test.startTest() and Test.stopTest() using Database.executeBatch(). Sample example is available here: https://www.infallibletechie.com/2018/11/how-to-test-batch-apex-result-in-test.html
Note:
The call to Database.executeBatch should be included within the Test.startTest and Test.stopTest block. The job executes after the call to Test.stopTest. Any asynchronous code included within Test.startTest and Test.stopTest is executed synchronously after Test.stopTest.

Leave a Reply