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
AkshuAkshu 

I want test class this extension class

public class VFControllerPosition {
    public Position__c po;
    
    public VFControllerPosition(ApexPages.StandardController controller) 
    {
        this.po =(Position__c)controller.getRecord();
    }
    
    public PageReference redirect1() 
    {
        PageReference p =new PageReference('/apex/JobportalTabpage2');
        return p; 
    }
    public PageReference redirect2()
    {
        insert po;
        PageReference p=new PageReference('/apex/JobportalTabpage3?id='+po.id);
        p.setredirect(true);
        return p;
        
    }
    public PageReference redirect3() 
    {
        PageReference p =new PageReference('/apex/JobportalTabpage4');
        p.setredirect(true);
        return p; 
        
    }
    public PageReference redirect4()
    {
        
        PageReference pr = new PageReference('/apex/JobportalTabpage5'+Apexpages.currentPage().getParameters().get('id'));
        
        pr.setredirect(true);
        return pr; 
        
        
        
    }
    
    
    
    
}
ShivankurShivankur (Salesforce Developers) 
Hi Akshay,

You can write a Test class like below:
@isTest

public class testVFControllerPosition{
    public static testMethod void testRedirect () {
        VFControllerPosition VFCntrl = new VFControllerPosition ();
        Position__c pos = new Position__c ();
        pageReference page2 = page.JobportalTabpage2;
        //pageReference page3 = page.JobportalTabpage3;
        //pageReference page4 = page.JobportalTabpage4;
        Test.setCurrentPage(page2);
        VFCntrl.pos.Name  = 'abc';
        insert pos;
        VFCntrl.save();
        system.assert(VFCntrl.pos.Id != null);
  apexPages.Currentpage().getParameters().put('Id',pos.id);
   }
}
Please note that, you may need to modify the code a little bit to fit with your case.

Additional references for help:
https://www.biswajeetsamal.com/blog/how-to-cover-pagereference-method-in-test-class/
https://www.forcetalks.com/salesforce-topic/how-to-write-test-class-for-code-coverage-of-pagereference-method-in-salesforce/
https://salesforce.stackexchange.com/questions/103178/test-class-for-pagereference-method

Hope above information helps, Please mark as Best Answer so that it can help others in the future.

Thanks.
AkshuAkshu
thanks Shivankur,