You need to sign in to do that
Don't have an account?
Madhu m
How to right test class to cover email logic in finish method of a batch class?
Below code is covered as I'm not sure how to fail the batch and move it to else part to do code coverage
public void finish(Database.BatchableContext bc)
{
AsyncApexJob a = [Select Id, Status, NumberofErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email, ExtendedStatus
from AsyncApexJob
Where Id =:bc.getJobId()];
String batchName = 'test_InvalidatingAsmtRequestBatch';
If(a.Status=='Completed' && a.NumberofErrors==0){
Database.executeBatch(new BCSA_BatchExtractSCRAData(),50);
}
else{
test_Utility bu = new BCSA_Utility();
bu.sendEmailNotificationOnBatchJobFail(batchName, a.Status, a.TotalJobItems, a.NumberOfErrors,a.ExtendedStatus);
}
}
}
public void finish(Database.BatchableContext bc)
{
AsyncApexJob a = [Select Id, Status, NumberofErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email, ExtendedStatus
from AsyncApexJob
Where Id =:bc.getJobId()];
String batchName = 'test_InvalidatingAsmtRequestBatch';
If(a.Status=='Completed' && a.NumberofErrors==0){
Database.executeBatch(new BCSA_BatchExtractSCRAData(),50);
}
else{
test_Utility bu = new BCSA_Utility();
bu.sendEmailNotificationOnBatchJobFail(batchName, a.Status, a.TotalJobItems, a.NumberOfErrors,a.ExtendedStatus);
}
}
}
Raj Vakati
By defaul it will cover if your code contains the batch database.executeBatch method on test.starttest and test.stoptest