I just used the new feature that allows me to call a SecondBatchable class from the finish() method of the FirstBatchable class.
global with sharing class FirstBatchable implements Database.Batchable<SObject>, Database.Stateful {
global void finish(Database.BatchableContext context) {
SecondBatchable batch = new SecondBatchable();
Database.executeBatch(batch, 5); // It even fails with value 1
}
...
}
This all works like a charm. But... All my tests of this class
@isTest
private static void testBatch() {
...
Test.startTest();
FirstBatchable batch = new FirstBatchable();
Database.executeBatch(batch, 200); // It even fails with value 1
Test.stopTest();
...
}
fail with the error:
System.UnexpectedException: No more than one executeBatch can be called from within a testmethod. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.
I guess the problem is as we chain TWO batches the Test.startTest and Test.stopTest bring the batchSize down to 1 but 1 + 1 != 1.
Any suggestions?!