You need to sign in to do that
Don't have an account?
Vishal Tiwari 36
How to Cover Catch block of batch class in your test class?
I have a class something like this:
global void execute(Database.BatchableContext BC, List<OBJ__c> objList) {
try{
if(objList!= null && objList.size() > 0 ){
delete objList;
}
}
catch(Exception ex){
System.debug('Exception');
}
}
My test class:
List<OBJ__C> cartList = [SELECT id from OBJ__C LIMIT 1];
Test.startTest();
BATCH_CLASS deleteCartBatch = new BATCH_CLASS ();
Database.executeBatch(deleteCartBatch, 200);
Test.stopTest();
How do I cover the catch block in this test class?
global void execute(Database.BatchableContext BC, List<OBJ__c> objList) {
try{
if(objList!= null && objList.size() > 0 ){
delete objList;
}
}
catch(Exception ex){
System.debug('Exception');
}
}
My test class:
List<OBJ__C> cartList = [SELECT id from OBJ__C LIMIT 1];
Test.startTest();
BATCH_CLASS deleteCartBatch = new BATCH_CLASS ();
Database.executeBatch(deleteCartBatch, 200);
Test.stopTest();
How do I cover the catch block in this test class?
To cover the catch block as well I think you should make sure the implementation in test class causes an exception there by that exception can be caught and in turn cover the catch block.
I hope this helps.
Regards,
Anutej
Did you get a way to induce an exception in your test class?
advancedmd.com (https://www.advancedmd.review/)