function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RahulRahul 

Need help in completing the test class. I got only 15% coverage. Thanks

public class BD_LeadTriggerHandler extends BD_TriggerHandler {

/*
*Author: Vivek
*Date: 01/13/2018
*Description: Defining Constructor
*/  
 public BD_LeadTriggerHandler(){}

/*
*Author: Vivek
*Date: 01/13/2018
*Description: Event handling methods
*/  
  public override void afterUpdate() {
    callAfterUpdateLogic();
  }
  
  public override void afterInsert() {
    callAfterInsertLogic();
  }
  
  public override void beforeUpdate() {
    callBeforeUpdateLogic();
  }
  
  public override void beforeInsert() {
    callBeforeInsertLogic();
  }


/*
*Author: Vivek
*Date: 01/13/2018
*Description: Methods called by Event handling methods which holds actual logic
*/ 
  public void callAfterUpdateLogic(){
    syncLeadRecordsWithBE(trigger.newMap.KeySet(),false);
  }
  
  public void callAfterInsertLogic(){
    syncLeadRecordsWithBE(trigger.newMap.KeySet(),true); 
  }
  
  public void callBeforeUpdateLogic(){
    //Add logic here
  }
  
  public void callBeforeInsertLogic(){
    //Add logic here
  }

/*
*Author: Vivek
*Date: 01/27/2018
*Description: Methods to handle synching functionality with backend in chunks
*/
public static List<Schema.FieldSetMember> getFields() {
        return SObjectType.Lead.FieldSets.BD_LeadIntegrationFields.getFields();
}

private static list<Lead> getLeadRecs(set<id> leadIds) {
    String query = 'SELECT ';
    for(Schema.FieldSetMember f : getFields()) {
            query += f.getFieldPath() + ', ';
    }
    query += ' Owner.Name FROM Lead WHERE ID IN: leadIds';
    return Database.query(query);
}

@future (callout=true)
public static void syncLeadRecordsWithBE(set<id> leadIds, Boolean isInsrt){
 BD_InterfaceConfigParameters__c serviceSettings;
 map<integer,list<Lead>> leadmap = new map<integer,list<Lead>>();
 if(leadIds != NULL){
    list<Lead> leadLst = getLeadRecs(leadIds);
    serviceSettings = BD_InterfaceConfigParameters__c.getValues(system.label.BD_INTERFACE_LeadRequest);
    integer chnkSize = serviceSettings != NULL && serviceSettings.BD_BatchSize__c != NULL && serviceSettings.BD_BatchSize__c < 50.0 
                       ? integer.valueOf(serviceSettings.BD_BatchSize__c) : 50;
    
    
    if(leadLst != NULL){
      integer cnt = 1;
      integer lpcnt = 1;  
      for(Lead ld: leadLst){
        
        if(lpcnt>chnkSize){
           cnt++;
           lpcnt = 1;
        }
        
        if(leadmap.containsKey(cnt)){
            leadmap.get(cnt).add(ld);
        }else{
              leadmap.put(cnt,new list<Lead>{ld}); 
        }
        lpcnt++;
          
      }
        system.debug('**********in Lead trigger, number of chunks:'+leadmap.size());
        system.debug('**********in Lead trigger, Leads in chunks:'+leadMap);
        
        if(!leadMap.isEmpty() && leadMap.size() < 100){
           for(integer i: leadMap.Keyset()){
             system.debug('**********in Lead trigger, in loop, calling service for chunk:'+i);
             BD_VO.LeadResults res = isInsrt ? new BD_GenIntegrationHelper().callObjectInsertSyncService(leadMap.get(i)) : new BD_GenIntegrationHelper().callObjectUpdateSyncService(leadMap.get(i));
           }
        }
    }   
 }
   

}
  

}

written test class :-
@isTest
private class BD_LeadTriggerHandler_Test {
     @isTest static void testAccountServicesLead() {
        
        Lead ld = new Lead();
        ld.lastName = 'Tulsani';
        ld.FirstName = 'Test';
        ld.status = 'New';
        ld.Email='Test@gmail.com';
        ld.phone='12345';
        ld.Mobilephone='12345';
        ld.company='Test comp';
        ld.Title='Test title';
        
        insert ld;
         
        Test.startTest();
        BD_LeadTriggerHandler l1 = new BD_LeadTriggerHandler();
       // l1.afterUpdate();
        l1.beforeUpdate();
        update ld;
        l1.beforeInsert();   
        //AccountService


        Test.stopTest();   
         
    }
}