You need to sign in to do that
Don't have an account?

Schedule Class code coverage is 0%
I have written a schedule class to update the lead source to web if the lead source is null. I have written test class as well. But code coverage is 0% can anyone help me so that code coverage is 100%
Class
global class LeadMaintanace implements Schedulable{
global void execute(SchedulableContext SC) {
List<Lead> li =[Select Id,Name from Lead where LeadSource = 'null' LIMIT 10];
List<Lead> lu= new List<Lead>();
if(!li.isEmpty()){
for(Lead ld:li){
ld.LeadSource = 'Web';
lu.add(ld);
}
}
update lu;
}
}
test class
@isTest
public class TestLeadMaintanace {
@testsetup
static void setup(){
List<Lead> li = new List<Lead>();
for(Integer i;i<10;i++){
Lead ld = new Lead(Company = 'Proseraa',LastName ='MN',Status = 'Working - Contacted');
li.add(ld);
}
update li;
}
static testmethod void TestJobSchedule(){
string sch = '0 30 12 2 20 ?';
Test.startTest();
string jobid=System.Schedule('SchedulableClass',sch, new LeadMaintanace());
List<Lead> li =[Select Id from Lead where LeadSource=null limit 10];
system.assertEquals(10,li.size());
test.stopTest();
}
}
Class
global class LeadMaintanace implements Schedulable{
global void execute(SchedulableContext SC) {
List<Lead> li =[Select Id,Name from Lead where LeadSource = 'null' LIMIT 10];
List<Lead> lu= new List<Lead>();
if(!li.isEmpty()){
for(Lead ld:li){
ld.LeadSource = 'Web';
lu.add(ld);
}
}
update lu;
}
}
test class
@isTest
public class TestLeadMaintanace {
@testsetup
static void setup(){
List<Lead> li = new List<Lead>();
for(Integer i;i<10;i++){
Lead ld = new Lead(Company = 'Proseraa',LastName ='MN',Status = 'Working - Contacted');
li.add(ld);
}
update li;
}
static testmethod void TestJobSchedule(){
string sch = '0 30 12 2 20 ?';
Test.startTest();
string jobid=System.Schedule('SchedulableClass',sch, new LeadMaintanace());
List<Lead> li =[Select Id from Lead where LeadSource=null limit 10];
system.assertEquals(10,li.size());
test.stopTest();
}
}
Please use below class and check the output