Hi,
I have wrote a batch class and now i am writing test class for it but i am getting this error. Argument must be an object that implements Database.Batchable
Batch class
global class CBatchCalculateRatingsHistoricalData { // Persistent variables global Boolean hasErrors {get; private set;} // Constructor global CBatchCalculateRatingsHistoricalData() { this.hasErrors = false; } global Database.QueryLocator start(Database.BatchableContext BC) { system.debug('Processing start method'); // Query string for batch Apex String query = ''; query += 'SELECT Id,name,Date_of_First_Order__c,Number_of_Orders__c FROM Account '; if(system.Test.isRunningTest()) query += ' LIMIT 200'; return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<sObject> objectBatch) { } global void finish(Database.BatchableContext BC) { } }
test class
@isTest(seeAllData = true) public class scheduledBatchable { static testMethod void Test_CBatchRatingsHistory() { System.Test.startTest(); CBatchCalculateRatingsHistoricalData b = new CBatchCalculateRatingsHistoricalData(); Database.executeBatch(b, 200); System.Test.stopTest(); } }
please tell me what is the issue with this code. If i am wrong then please help me to get it right.
Thanks
Anu
Hey Anu,
Try below code :-
@isTest(seeAllData = true)
public class scheduledBatchable
{
static testMethod void Test_CBatchRatingsHistory()
{
String query = 'SELECT Id,name,Date_of_First_Order__c,Number_of_Orders__c FROM Account';
List<Account> accList = new List<Account>();
for (Integer i=0;i<200;i++) {
Account acc = new Account(
Name='Test Account' + i);
accList.add(acc);
}
insert accList;
System.Test.startTest();
CBatchCalculateRatingsHistoricalData b = new CBatchCalculateRatingsHistoricalData();
Database.executeBatch(b, 200);
System.Test.stopTest();
}
}
Hi,
In your apex class add the (implements Database.Batchable<sObject>) line,
like
global class CBatchCalculateRatingsHistoricalData implements Database.Batchable<sObject> {
//your code
for more info read theblogreaders.com