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
Deepika RahangdaleDeepika Rahangdale 

test class of vf extension and controller

public class VFControllerPosition{
   //private final  Position__c pos1;
    private  ID recordId;
    public Position__c pos{set;get;}
private ApexPages.StandardController controller;
public VFControllerPosition(ApexPages.StandardController controller) {
this.pos = (Position__c)controller.getRecord();
    
}
    //Controller page 1
    public VFControllerPosition(){
    pos = new Position__c();
         recordId= ApexPages.currentPage().getParameters().get('id');
       
      pos = [Select id,Position_Title__c,Status__c,Name,Active__c from Position__c ];
        system.debug('vf6');
      
    }
        
   //*******Controller method for VF page 1************    
public PageReference Next() {
    insert pos;
PageReference VFpositionpage2 = Page.VFpositionpage2;
       VFpositionpage2.setRedirect(true);
        VFpositionpage2.getParameters();
            //.put('id',controller.getId());
        return page.VFpositionpage2; 
}
     //********Controller page 2********
  public PageReference save() {
        insert pos;
  PageReference VFpositionpage3= Page.VFpositionpage3;
         VFpositionpage3.setRedirect(true);
        VFpositionpage3.getParameters(); 
        return page.VFpositionpage3; 
    
}
     //*****************Controller page 3***********
     public PageReference redirect3(){
 PageReference VFpositionpage4= Page.VFpositionpage4;
         VFpositionpage4.setRedirect(true);
        VFpositionpage4.getParameters(); 
        return page.VFpositionpage4; 
         
         
    }
     public PageReference redirect4() {  
        
   //  if(controller.redirect4() != null) {
       PageReference pg  = new PageReference('/'+recordId);
        pg.setRedirect(true);
        return pg;


}
}
PriyaPriya (Salesforce Developers) 
Hi Deepika,

Please try this sample code and modify it accordingly :- 
 
@isTest
public class VFControllerPositionTest {
    private static testMethod void testAutoRun() {
        test.startTest();
        PageReference pageRef = Page.yourPageName;
        Position__c pos = new Position__c(name ='Test',status = 'some status',Title=''....);
        insert pos;
        Test.setCurrentPage(pageRef);
        ApexPages.StandardController sc = new ApexPages.standardController(pos);
        VFControllerPosition vfCon = new VFControllerPosition(sc);
        System.assertNotEquals(null,vfCon.redirect1());
        vfCon.save();
        vfCon.next();
        
        test.stopTest();
    }
    
}


 
If above code helps, please mark it as best answer.

Regards,
Priya Ranjan
Deepika RahangdaleDeepika Rahangdale
hey @priya 
thanks for response 
I used this code but not getting 100% code coverage 
this is my test class and above my VF controller class 
please help ASAP

@istest
public class TestVFControllerPosition {
  private static testMethod void testAutoRun() {
        test.startTest();
        PageReference pageRef = Page.vfpositonpage1;
      PageReference pageRef2 = Page.vfpositionpage2;
      PageReference pageRef3 = Page.vfpositionpage3;
        Position__c pos = New Position__c();
     pos.Position_Title__c='JR. TEST';
    Pos.Name='Engineer';
        pos.Max_Pay__c='5000';
            pos.Min_Pay__c='70000';
            pos.Type__c='Technical';
      pos.status__C='new';
        insert pos;
        Test.setCurrentPage(pageRef);
      Test.setCurrentPage(pageRef2);
      Test.setCurrentPage(pageRef3);
        ApexPages.StandardController sc = new ApexPages.standardController(pos);
        VFControllerPosition vfCon = new VFControllerPosition(sc);
        System.assertNotEquals(null,vfCon.next());
       
        vfCon.next();
        vfCon.save();
      vfCon.redirect3();
      vfCon.redirect4();
        test.stopTest();
    
    
}