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
bharath kuamarbharath kuamar 

please help me with this test class for below class coverage increase

Hi, i have written the test clss for the below class but the coverage shows only 60%, please help me to increase the coverage

global class PDFGencontroller
{
String LongDate = ' ';
String hostUrl;
String PreferId=System.currentPagereference().getParameters().get('id'); 
public PDFGencontroller()
{
 hostUrl = 'https://'+ ApexPages.currentPage().getHeaders().get('Host') +'/servlet/servlet.FileDownload?file=';
  }

public list<contact> getcontactinfo()
{
   
    system.debug('<<<<<<<<<<<<<Inside getContactInfo>>>>>>>>>>>>>>'+PreferId);
    List<Contact> con = new List<Contact>();
    Preference__c  p=[select opportunity__c from preference__c where id=:PreferId];
    OpportunityContactRole oRole = [Select ContactId from OpportunityContactRole Where OpportunityId=:p.opportunity__c ];
    con =[select firstname,lastname,Birthdate,Email,Phone from contact where id=:oRole.ContactId];
  
    return con;
    
}

 public list<Preference__c> getPreferenceInfo()
 {
   
    List<Preference__c> con1 = new List<Preference__c>();
    con1=[select name,Payment_Modes__c,payment_frequency__c,duration__c  from preference__c where id=:PreferId];
    return con1;
   }
   
   public list<commitment__c> getCommitmentInfo()
   {
    
     List<commitment__c> con2 = new List<commitment__c>();
    con2=[select name,Commitment_Type__c,Start_Date__c,End_Date__c,status__c from commitment__c where preference__c=:PreferId];
    return con2;
    
   }
   
 public list<Payment_Schedule__c> getPaymentInfo()
 {
   
    
    List<Payment_Schedule__c> con3 = new List<Payment_Schedule__c>();
    Preference__c p=[select opportunity__c from preference__c where id=:PreferId];
    con3=[select name,Payment_Start_Date__c,Payment_End_Date__c,Payment_Frequency__c,Payment_Mode__c,Amount__c  from Payment_Schedule__c where Opportunity__c =:p.opportunity__c ];
     
    return con3;

   }
   
    public String getLongDate()
     {
        Datetime cDT = System.now();
        LongDate = cDT.format('MMMM d,yyyy');
        return LongDate;
      }
      
      //test methods for the class "PDFGencontroller"
 
  static testmethod void PDFGencontroller()
      {
       
        PDFGencontroller pdfn = new PDFGencontroller();
        String hostUrl='_https://'+ 'ER201109-0000570' +'/servlet/servlet.FileDownload?file=';
        Preference__c pref = new Preference__c();
        pref.opportunity__c='00690000006yeky';
        insert pref;
        
        //OpportunityContactRole oRole = new OpportunityContactRole();
        //oRole.ContactId ='0039000000CvOJa';
       // insert oRole;

        Contact con = new Contact();
        con.firstname='test';
        con.lastname='date';
        con.Birthdate=date.today();
        con.Email='abc@abc.com';
        con.Phone ='6262323';
        insert con;
        
        //pdfn.getcontactinfo();

        Preference__c con1= new Preference__c();
        con1.Payment_Modes__c='cash';
        con1.payment_frequency__c='Annually(Full Payment)';
        con1.duration__c='3';
        insert con1;
        pdfn.getPreferenceInfo();
        commitment__c comm = new commitment__c();
        comm.Commitment_Type__c='Sponsor a child';
        comm.status__c='assigned';
        insert comm;
        
        pdfn.getCommitmentInfo();
                 //  pdfn.getPaymentInfo();  
        Payment_Schedule__c payy =new Payment_Schedule__c();
                  // payy.getPaymentInfo();  
        payy.name='ghd';
         payy.Payment_Start_Date__c=date.today();
          payy.Payment_End_Date__c=date.today();
           payy.Payment_Frequency__c='Annaul';
            payy.Payment_Mode__c='Cash';
             payy.Amount__c=50;
             insert payy;

          
        pdfn.getLongDate();
         
         
         
       Preference__c con11= new Preference__c();
       con11.opportunity__c='00690000006yeky';
       //con11.name='a0990000008T5DB';
       insert con11;
       Payment_Schedule__c payment = new Payment_Schedule__c();
       payment.name='testpayment';
       payment.Payment_Start_Date__c=date.today();
       payment.Payment_End_Date__c=date.today();
        payment.Payment_Frequency__c='Annual(fullpayment)';
        payment.Payment_Mode__c='Cash';
        payment.Amount__c=50;
         insert payment;
        // pdfn.getPaymentInfo();
     
}
}

getPaymentInfo() method and getcontactinfo()method is not covered, please help me out

 

Jerun JoseJerun Jose
The two methods are not being covered because the two methods are not called.

I see that you have commented the calls to those methods. All you will need to do is to uncomment the calls.
bharath kuamarbharath kuamar

i tried to call these two mtehods , but giving a test failture

Jerun JoseJerun Jose
Then you will have to fix those failure reasons. Not calling them will not give you code coverage.
Face your fears :P
tomcollinstomcollins

... or delete the methods if they don't work.  ;-)