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
arun kumar.ax887arun kumar.ax887 

How to write a Test Case for a Custom Controller

 

I have a requirement, where in I need to write a controller for generating PDFs using Visualforce page.   I have written the controller and the Visualforce page for generating pdf,  both are working properly, but I am unable to write the test class for the controller, could any one suggest how to write a test class.    

 

 

Apex Custom Controller 

 

public class Dev_DR_Controller
{
     public Dev_DR_Controller(ApexPages.StandardSetController controller)
   {
   
     }

 

 
    Private DR__c dr;
    Private DR_Payment_Line_Item__c[] dpli;
    

//public final DR__c dr;


public Dev_DR_Controller()
{

 dr = [select Id, name, Patient__c, Patient__r.Name ,
 Branch__r.Name , Workflow_Branch_Address_1__c,
 Workflow_Branch_Address_2__c, Workflow_Branch_City__c,
 Workflow_Branch_Fax__c, Workflow_Branch_Name__c,
 Workflow_Branch_Phone__c, Workflow_Branch_Postcode__c,
 Dev_DR_Day__c,Dev_DR_Month__c,Dev_DR_Year__c,
 Workflow_Branch_State__c,Amount_Paid__c,Rep__c,
 Amount__c,Item_Code__c,Item__c,
 balance_Due__c,Item__r.Item_Code__c,Item__r.Name,  
 Bill_to__c, Date__c,
 Patient_Identification__c,Patient__r.Workflow_Patient_Identification__c
 from DR__c where id = :ApexPages.currentPage().getParameters().get('id')];

 

 DPLI = [select Id,name, Amount__c,  Dev_DR_PLI_Record_Type__c,Dev_DR_PLI_Day__c,Dev_DR_PLI_Month__c,Dev_DR_PLI_Year__c,  
             Bank_Terminal__c,Credit_Card__c, Date__c, Deposit_Receipt_Number__c, Payment_Description__c,
             Payment_Reference__c, Remarks__c from DR_Payment_Line_Item__c where Deposit_Receipt_Number__c =:dr.id];

 

}


public void setDR(DR__c dr)
{
  this.dr=dr;
}

public void setDPLI(DR_Payment_Line_Item__c[] dpli)
{
    this.dpli=dpli;
}

public DR__c getDR()
{
    return this.dr;
}

public DR_Payment_Line_Item__c[] getDPLI()
{
    return this.DPLI;
}

}

 

 

 

Kindly suggest a better solution for writing TestCase to a Custom Controller.

 

 

 

Best Regards

 

Arun