+ Start a Discussion
NaziNazi 

How to cover execute method in test class for Batch class

 Hi
I called the batch class in my apex class method.when I am writting test class for that batch class its not covering the execute method.Is there any solution ?

Thanks.
Andy on CloudAndy on Cloud
Two options, #1 you could submit the batch between test.starttest() and test.stoptest() in your test method using database.executeBatch() method to submit the Batch.  #2 delegate all your work in execute() into another helper class and cover that class.
NaziNazi
Thanks Andy can u pls give some example for 2nd option
Amit Chaudhary 8Amit Chaudhary 8
Hi Nazira,

You need to create test data in your test class according to your start method then only execute method will execute.