function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sandeep YadavSandeep Yadav 

database.executeBatch is not covered by test class

Hi everyone,
I am calling this method from test class and it is not covering the statements inside if condition.
what's going wrong!!
Any help would be appreciate.User-added image
v varaprasadv varaprasad
Hi Sandeep,

Remove test.isRunningtest line and check once.

Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
More Info : 

https://help.salesforce.com/articleView?id=000205831&type=1

https://developer.salesforce.com/forums/?id=9060G000000Ub1HQAS


Thanks
Varaprasad
@For SFDC Support: varaprasad4sfdc@gmail.com
Blog: http://salesforceprasad.blogspot.com/

Salesforce latest interview questions  :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1





 
Sandeep YadavSandeep Yadav
Hi varaprasad,

I already checked it.
when i remove Test.isRunningTest() from the code then it gives the error like this:
System.UnexpectedException: Start did not return a valid iterable object.
 
Yogeshwar TailorYogeshwar Tailor
Hi Sandeep,

Please let me know you wrote below line in your test class or not before calling the Start_CBI_BatchJob() method?
 
Database.executeBatch(new BatchToCopyCBIDataToNextYear('2016','2017')); /* Pass argument according to you*/

Let me know if it will not help.

Thanks,
Yogesh
Sandeep YadavSandeep Yadav
Hi Yogeshwar,

I wrote this statement before calling Start_CBI_BatchJob() method.
Test.startTest();
        Database.executeBatch(new BatchToCopyCBIDataToNextYear(fromSel,toSel));
        pbar.Start_CBI_BatchJob();
 Test.stopTest();
pbar is the class instance from which i calling the method.
Still I got the same error:-
System.UnexpectedException: Start did not return a valid iterable object.
 
Yogeshwar TailorYogeshwar Tailor
Hi Sandeep,

Can you share your batch class ? So i can be more clear.
 
Check below url it might helpful for you.

https://developer.salesforce.com/forums/?id=906F0000000DCb9IAG


Thanks,
Yogesh
Gmail : yogeshwer1994@gmail.com