I've been staring at this for far too long so would VERY MUCH appreciate help on what's going on here! This should be a relatively straightforward Batch Apex from the Asychronous Apex trail.
When I run the test, it runs the start and finish methods and skips execute entirely.
Test class:
@isTest
public class LeadProcessorTest {
@isTest
public static void testLeadProcessor() {
List<Lead> listOfLeads = new List<Lead>();
for(Integer i = 0; i < 200; i++) {
Lead l = new Lead();
l.LastName = 'Testing' + i;
l.Company = 'Test Company ABC';
l.Status = 'Open - Not Contacted';
l.LeadSource = 'Web';
listOfLeads.add(l);
}
System.debug('Number of leads created ' + listOfLeads.size());
insert listOfLeads;
}
@isTest static void test() {
Test.startTest();
LeadProcessor lp = new LeadProcessor();
Id batchId = Database.executeBatch(lp);
Test.stopTest();
}
}
Lead Processor class:
global class LeadProcessor implements Database.Batchable<sObject> {
Integer recordsProcessed = 0;
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator('SELECT Id, LeadSource FROM Lead');
}
public void execute(Database.BatchableContext bc, List<Lead> leads){
List<Lead> myLeads = new List<Lead>();
for(Lead currl : leads) {
currl.LeadSource = 'Dreamforce';
myLeads.add(currl);
recordsProcessed += 1;
}
update myLeads;
}
public void finish(Database.BatchableContext bc) {
System.debug('Number of records processed: ' + recordsProcessed);
}
}