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
sesidhar ponnada 8sesidhar ponnada 8 

please find test class for this Apex class its urgent..

public class BatchInsertionExtension {

    sample_request__c smpreqObj;
    public List<BatchWrapper> batchWrpprList{set;get;}
    public List<batch__c> delList;
    public List<SelectOption> options {set;get;}
    public Integer rmvBatchIndex{set;get;}
    public String delBatchId{set;get;}
    Public boolean tableFlag{set;get;}
    Public boolean msgFlag{set;get;}
    public static integer delBatchCount=0; 
    Public Id samReqId;
    
    
    public BatchInsertionExtension(ApexPages.StandardController controller) {
    samReqId = controller.getid();
    smpreqObj = [select id,Product_1_Name__c,Product_2_Name__c,Product_3_Name__c,Product_4_Name__c from sample_request__c where id =:controller.getid() ];
    options = new List<SelectOption>();
   
    batchWrpprList = new List<BatchWrapper>(); 
    
    batchWrpprList = QueryBatch();
    delList = new list<batch__c>();
  
        
    if(batchWrpprList.size()>0)
    {
     tableFlag=true;
    }
    else
    {
    tableFlag=false;
    }
    
    // Adding select list options
    
    options.add(new SelectOption('-None-','-None-'));
    If(smpreqObj.Product_1_Name__c!=null && !string.isblank(smpreqObj.Product_1_Name__c))
        options.add(new SelectOption(smpreqObj.Product_1_Name__c,smpreqObj.Product_1_Name__c));
    If(smpreqObj.Product_2_Name__c!=null && !string.isblank(smpreqObj.Product_2_Name__c))
    options.add(new SelectOption(smpreqObj.Product_2_Name__c,smpreqObj.Product_2_Name__c));
    If(smpreqObj.Product_3_Name__c!=null && !string.isblank(smpreqObj.Product_3_Name__c))
    options.add(new SelectOption(smpreqObj.Product_3_Name__c,smpreqObj.Product_3_Name__c));
    If(smpreqObj.Product_4_Name__c!=null && !string.isblank(smpreqObj.Product_4_Name__c))
    options.add(new SelectOption(smpreqObj.Product_4_Name__c,smpreqObj.Product_4_Name__c));
 
    }
    
    public class BatchWrapper
    {
      Public String selectedStr{get;set;}
      Public String batchStr{get;set;}
      Public String indexStr{set;get;}
      public String IdStr{set;get;}     
    
    }
    
    
    public void addBatch()
    {
       BatchWrapper btIns = new BatchWrapper();
       btIns.selectedStr='-None-';
       btIns.indexStr= String.valueOf(batchWrpprList.size());
       system.debug('check add'+btIns.indexStr);
       batchWrpprList.add(btIns); 
       tableFlag=true;
    
    
    }
    
    public void removeBatch()
    {
    
    integer indexCount=  rmvBatchIndex- 1;
    batchWrpprList.remove(indexCount);
   
   
      if(!String.isBlank(delBatchId))
      {
       batch__c btObj = new batch__c(id=delBatchId);
       try
       {
        delete btObj ;
        
       }
       catch(dmlexception ex)
       {
        msgFlag=true;
        apexpages.addMessages(ex);
        
       }
       catch(exception e)
       {
        msgFlag=true;
        apexpages.addMessages(e);
        
       }
      
      
      } 
   // delCount = delCount+1;
    }
    
    public void saveBatch()
    {
     List<batch__c > btUpdList = new List<batch__c >();
        
        for(BatchWrapper batchIns:batchWrpprList)
        {
          batch__c btObj = new batch__c();
         If(!String.isBlank(batchIns.IdStr))
         {
              btObj.id = batchIns.IdStr;
         }
          btObj.batch__c= batchIns.batchStr;
          btObj.Product__c = batchIns.selectedStr;
          btObj.Sample_Request__c =samReqId ;
          btUpdList.add(btObj);
        
        }
        
        try
        {
          upsert btUpdList;
          batchWrpprList.clear();
          batchWrpprList = QueryBatch();
          apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Batch Details Saved');
          apexpages.addmessage(msg);
        }
        catch(dmlexception ex)
        {
         msgFlag=true;
         apexpages.addMessages(ex);
         
        }
        catch(exception e)
        {
         msgFlag=true;
         apexpages.addMessages(e);
         
        }
        
    
    }
    
    public List<BatchWrapper> QueryBatch()
    {
      List<BatchWrapper> currbatchWrpprList = new List<BatchWrapper>();
    
   for( batch__c currBatchList : [select id, Name,batch__c,Product__c,Batch_Identifier__c from batch__c where Sample_Request__r.id=:samReqId ] )
   {
       BatchWrapper btIns = new BatchWrapper();
       btIns.selectedStr=currBatchList.Product__c;
       btIns.indexStr= String.valueOf(currbatchWrpprList.size());
       system.debug('Check 12121'+btIns.indexStr);
       btIns.IdStr= currBatchList.id;
       btIns.batchStr=currBatchList.batch__c;
       currbatchWrpprList.add(btIns); 
   
   }
   
   return currbatchWrpprList;
    
    
    }
    

}
BHinnersBHinners
Here's a resource with sample code to get you started, look for the section on controllers: https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods

Here is another good resource: http://jessealtman.com/2013/09/proper-unit-test-structure-in-apex/