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
NikunjVadiNikunjVadi 

Page-reference Testing

Help me out with testing this class :
public PageReference Next_FoundationWalls(){
         if(myDoc.body != null){
         myDoc.parentId = myCustomObject.Id;
         myDoc.Name='FoundationWalls';
         insert myDoc;
         myDoc.body=null;}
         pageid=ApexPages.currentPage().getParameters().get('id');
         obj.Id=pageid;
         obj.Basement_Foundation_Walls__c = FoundationWalls;
         obj.Foundation_Wall_Notes__c=FoundationWallsNotes;
         update obj;
         Pagereference ref = new Pagereference('/apex/Floor_drain?id='+pageid);
         ref.setRedirect(true);
         return ref;
         }

mydoc is attachment type.

i tried this
@isTest
public class HomeEvaluation_Test {
    static testMethod void HomeEvaluationtest()
    {
        HomeEvaluation__c HE = new HomeEvaluation__c();
        HomeEvaluationController HC = new HomeEvaluationController(new ApexPages.StandardController(new HomeEvaluation__c()));
        String pageid;
        HE.id= pageid;
        HC.getItems();
        HC.getYesOrNO();
        HC.getDucting();
        PageReference pageRef = new Pagereference(''/apex/Floor_drain?id='+pageid);
        Test.setCurrentPage(pageRef);        
    }
}

it isnt coverining pagerefrence. 
Controller is much big, but i know how to cover other things. 
Thank you
sandeep sankhlasandeep sankhla
Hi,

You can create instance of the class and the call this pagereference method and before calling this method you can set the page id as 

ApexPages.currentPage().getParameters().put('id', obj.Id);

provide the id which should be in page then it will work..

Thanks
Sandeep

 
Himanshu ParasharHimanshu Parashar
Hi Nikunj,

You need to call your method as following from Test class.
 
//put your parameter 
PageReference.getParameters().getParameters().put('id',pageid);
//call method
PageReference pageRef = HC.Next_FoundationWalls();
//Assert return
System.assertNotEquals(null,pageRef); 
System.assertEquals('/apex/Floor_drain?id=' + pageid,pageRef.getUrl());

Thanks,
Himanshu
NikunjVadiNikunjVadi
i tried this still not working
@isTest
public class HomeEvaluation_Test {
    static testMethod void HomeEvaluationtest()
    {
        HomeEvaluation__c HE = new HomeEvaluation__c();
        HomeEvaluationController HC = new HomeEvaluationController(new ApexPages.StandardController(new HomeEvaluation__c()));
        String pageid;
        pageid = HE.id;
        ApexPages.currentPage().getParameters().put('id', HE.Id);

        HC.getItems();
        HC.getYesOrNO();
        HC.getDucting();
        PageReference pageRef = new Pagereference('/apex/Ventilation_Ducting?id='+HE.id);
        Test.setCurrentPage(pageRef);       
    }
}


Himanshu , i tried your solution also , test is getting failed.
Thanks for the help