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
Kunal Purohit 4Kunal Purohit 4 

How to write test case for custom controller VF page?

Hello All, can someone help me to write test case for below custom controller VF page?

public with sharing class JournalPage1 {

public integer limitvalue=5;
public integer offsetvalue=0;
public integer papersize=0;


    public Date endDate { get; set; }
    
    //public List<Research_Paper__C> Research{get;set;}

    public Date startDate { get; set; }
    
    public List<Author_Research_Paper__c> AuthList { get; set; }

    public boolean Showdetailsflag { get; set; }

    public List<wrapJournalPage1> WrapList { get; set; }

   

    public PageReference lastPage() {
    offsetValue = papersize - limitValue;
    callQuery();
    
        return null;
    }


    
    
    public PageReference nextPage() {
  offsetValue = offsetValue + LimitValue;
    callQuery();
        return null;
    }


    public PageReference previousPage() {
   if(offsetValue > 0){
    offsetValue = offsetValue - LimitValue;
    callQuery();
    }
        return null;
    }


    public PageReference firstPage() {
    offsetValue = 0;
    callQuery();
        return null;
    }
 public void callQuery(){
 WrapList = new List<wrapJournalPage1>();
// list<Research_Paper__c> rlist=[Select id from Research_Paper__c];
  papersize=count;
  for(Research_Paper__c rc:[Select Id,Name, Paper_Title__c,Name_of_Primary_Author__c,Status__c,Publication_Date__c from Research_Paper__c  limit:limitvalue OFFSET:offsetvalue]){
               wrapJournalPage1 obj=new wrapJournalPage1(rc);
                            Wraplist.add(obj); 
                            }                          
 }

    public void Showdetails() {
         List<Id> rpID = new List<Id>();
         for(wrapJournalPage1 wp : wrapList)
         {
         if(wp.flagWrap==true)
         {
         rpID.add(wp.rcWrap.Id);
         }
         }
         for(Id i : rpID)
         {
     AuthList=[Select Id, Research_Paper__r.Name, Research_Paper__r.Paper_Title__c, Author__r.Name,
                      Research_Paper__r.Status__c, Research_Paper__r.Submission_Date__c
                       From Author_Research_Paper__c
                       Where Research_Paper__c =: i];
         }
         
         Showdetailsflag=true;
    }


   // public Boolean selectionflag { get; set; }

    public void updated() {
        Research=[Select id from Research_Paper__c];
                                
    count=Research.size();
    }


    public Integer count { get; set; }

    public List<Research_Paper__c> Research { get; set; }
    
    public JournalPage1()
{
Research=new list<Research_Paper__c>();

}

    public PageReference Show() {
    
     WrapList = new List<wrapJournalPage1>();
    
    if(startDate!=null && endDate!=null)
    {
         Research=[Select Id,Name, Paper_Title__c,Name_of_Primary_Author__c,Status__c,Publication_Date__c from Research_Paper__c where Publication_Date__c>=:startDate AND
                                         Publication_Date__c<=:endDate limit:limitvalue OFFSET:offsetvalue];
                            count=Research.size();
                            for(Research_Paper__c rc:Research)
                            {
                            wrapJournalPage1 obj=new wrapJournalPage1(rc);
                            Wraplist.add(obj);
                            }
    }
    
        return null;
    }


    
    
    Public class wrapJournalPage1{
    
    Public Research_Paper__c rcWrap{get; set;}
    public boolean flagWrap{get;set;}
    
    public wrapJournalPage1(Research_Paper__c rc){
            this.rcWrap=rc;
            this.flagWrap=false;
    }
    
    }
}
AbhishekAbhishek (Salesforce Developers) 
Kunal,

https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines

Try Suggestions as mentioned in the above article it will help you.

I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.