I've writtem a test class for my batch class. I've followed everything that was described in this question. Still getting the same error. Can anyone help me to find the problem in my code?
System.UnexpectedException: No more than one executeBatch can be called from within a test method. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.
Start method
String queryFields = 'SELECT Id, Name, BM_DPM_Date__c, BM_DPM_FC__c, BM_DPM_RecommendedFT_MH__c, ExtraFT__c, BM_DPM_PartTimeMH_Average__c, ExtraPT__c ';
String queryObjectAPIName = 'FROM BM_DailyProductivityManagement__c ';
String queryWhereClause = 'WHERE BM_DPM_Date__c >=: startDate AND BM_DPM_Date__c <=: endDate ';
String queryOrderby = 'ORDER BY BM_DPM_Date__c ASC';
String query = queryFields + queryObjectAPIName + queryWhereClause + queryOrderby + queryOrderby + (Test.isRunningTest() ? ' LIMIT 200' : '');
return Database.getQueryLocator(query);
Finish method
global void finish(Database.BatchableContext dbc){
if (!Test.isRunningTest()){
BM_26_CL_FT_Schedule batch = new BM_26_CL_FT_Schedule();
batch.startDate = startDate;
batch.endDate = endDate;
Database.executeBatch(batch, 1);
}
}
Excerpt from my test class
System.Test.startTest();
BM_25_OP_FT_Schedule newBatch = new BM_25_OP_FT_Schedule();
newBatch.startDate = startDate;
newBatch.endDate = endDate;
Database.executeBatch(newBatch, 1);
System.Test.stopTest();