How to write test class for Schedulable class
Apex class:
global class update_Account implements Schedulable
{
public list<Change_Request__c> lstChnReq = new list<Change_Request__c>();
Map<Id, Account> mapAccount = new Map<Id, Account>();
public list<Change_Request__c> lstChnReqUpdate = new list<Change_Request__c>();
global void execute(SchedulableContext sc)
{
Map<String,Schema.RecordTypeInfo> rtMap = Schema.SObjectType.Account.getRecordTypeInfosByName();
Id rtLeadID = rtMap.get('Lead').getRecordTypeId();
lstChnReq = [select Id,Updated__c,Lead_Merchant_Name__c,New_Value__c,Request_Type__c from Change_Request__c where Updated__c= False and Lead_Merchant_Name__c!= NULL order by CreatedDate asc];
system.debug('--lstChnReq--'+lstChnReq);
//and Lead_Merchant_Name__r.recordtypeId = :rtLeadID
for(Change_Request__c CR:lstChnReq)
{
Account acc= new Account (id=CR.Lead_Merchant_Name__c);
Change_Request__c chReq = new Change_Request__c(id=CR.Id);
if(CR.Request_Type__c=='First Name'){
acc.FirstName =CR.New_Value__c;
chReq.Updated__c= true;
system.debug('--CR.Updated__c--'+CR.Updated__c);
system.debug('--acc.FirstName--'+acc.FirstName);
}
if(CR.Request_Type__c=='Last Name'){
acc.LastName =CR.New_Value__c;
chReq.Updated__c= true;
system.debug('--acc.LastName--'+acc.LastName);
}
if(CR.Request_Type__c=='Phone'){
acc.Phone =CR.New_Value__c;
chReq.Updated__c= true;
system.debug('--acc.Phone--'+acc.Phone);
}
if(CR.Request_Type__c=='Alternate Email'){
acc.Alternate_Email__c =CR.New_Value__c;
chReq.Updated__c= true;
system.debug('--acc.Alternate_Email__c--'+acc.Alternate_Email__c);
}
/*
if(CR.Request_Type__c=='Contact Email'){
system.debug('--acc.RecordTypeId--'+acc.RecordTypeId);
//if(acc.RecordTypeId == rtLeadID){
acc.Subscription_Email__c =CR.New_Value__c;
chReq.Updated__c= true;
system.debug('--acc.Subscription_Email__c--'+acc.Subscription_Email__c);
//}
}
*/
mapAccount.put(acc.id,acc);
lstChnReqUpdate.add(chReq);
}
system.debug('--lstChnReqUpdate--'+lstChnReqUpdate);
update mapAccount.values();
update lstChnReqUpdate;
}
}
Test class:
@isTest
public class TestUpdate_Account {
static testmethod void TestUpdate_Account()
{
Test.starttest();
account a = new account();
a.FirstName='Mark';
a.lastName='test';
a.phone='12345678';
//a.Alternate_Phone__c ='23456789';
a.Alternate_Email__c ='test@gmail.com';
insert a;
Change_Request__c cr = new Change_Request__c();
cr.Lead_Merchant_Name__c=a.id;
cr.Request_Type__c='First Name';
cr.New_Value__c='test';
cr.Updated__c=true;
insert cr;
Test.stoptest();
}
}
Still my test class passed and 0% coverage how to increase code coverage for scheduler class?