how to write test class for batch class ? this covers only 44%
global Class Batchsample implements Database.Batchable<sObject>{
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator([
select id from Attendance__c
where Login_Date__c = LAST_MONTH AND
Leave_Type__c not in ('SL','EL','AL','Half Day')
]);
}
global void execute(Database.BatchableContext BC,list<Attendance__c> scope){
delete scope;
}
global void finish(Database.BatchableContext BC){
}
}
test class
@isTest
public class batchsampleTest
{
static testMethod void test1()
{
list<Attendance__c> sample = new list<Attendance__c>();
for(Integer i = 0; i< 100; i++){
Attendance__c att = new Attendance__c(Login_Time__c= Date.Today()-30,Project__c = 'AHM',Leave_Type__c = 'SL');
sample.add(att);
}
insert sample;
Test.startTest();
batchsample bs = new batchsample();
DataBase.executebatch(bs);
Test.stopTest();
}
}