Test Class for Batch Apex in Salesforce

Test Class for Batch Apex in Salesforce

Sample Batch Class:


Test class for above Batch Class:
@isTest
public class AccountUpdateTest {
    static testMethod void test() {
        Database.QueryLocator QL;
        Database.BatchableContext BC;
        List<Account> AcctList = new List<Account>();
        AccountUpdate AU = new AccountUpdate(‘Name’, ‘Test’);
        QL = AU.start(bc);
       
        Database.QueryLocatorIterator QIT =  QL.iterator();
        while (QIT.hasNext())
        {
            Account Acc = (Account)QIT.next();           
            System.debug(Acc);
            AcctList.add(Acc);
        }       
       
        AU.execute(BC, AcctList);
        AU.finish(BC);       
    }
}

Leave a Reply