This is my test method for batch process:
static testMethod void TST_testBatch() {
Test.startTest();
testBatch b = new testBatch();
Database.executeBatch(b);
Test.stopTest();
}
But I am getting this exception:
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.
I have @isTest(SeeAllData=false)
at top, but cannot figure out what is causing this error.
UPDATE: I have even kept finish methods as shown below:
global void finish(Database.BatchableContext BC){
if(!Test.isRunningTest())
Database.executeBatch(new testBatch()));
}
UPDATE 2:
testBatch execute method:
global void execute(Database.BatchableContext BC, List<sObject> scope){
Map<Id,SomeOnject> ms = new Map<Id,SomeOnject>();
for(sObject s: scope)
ms.put(s.Id,(SomeOnject)s);
if(ms.size() > 0){
Map<Id,SomeOnject> toUpdate = new Map<Id,SomeOnject>();
SomeOnject tmp;
for(Territory__c t: [SE********************************]){
tmp = ms.get(t.SFDC__c);
tmp.SFDCTerritory__c = t.Id;
tmp.Territory_Nr__c = t.TerritoryNr__c;
tmp.Territory_Account__c = t.Territory_Account__c;
toUpdate.put(tmp.Id,tmp);
}
if(toUpdate.size() > 0){
TerritoryUtils.runUpdateSFDC = false;
update toUpdate.values();
}
}
}
Start Method:
global Database.QueryLocator start(Database.BatchableContext BC){
String query = 'SELECT *************';
return Database.getQueryLocator(query);
}