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
NakataNakata 

How to test redirect in test class

Good day, 

 

Appreciated someone please enlighten me how could i test the current page is the page that re-directed in test class?

 

for instance, 

if i have set my current page from test class

 

PageReference pageRef = new PageReference('/apex/mycurrentpage);

 Assume one method executed later and the method call redirect to another page at the end.

 

my question is how should i write a test method for it ? 

 

try using following, but it give me pagereference of '/apex/mycurrentpage', what i expecting is '/apex/nextpage'

 

PageReference curpageRef = ApexPages.currentPage();

 

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

Test.setCurrentPage is what changes pages while testing. Instead, you should check the return value of the function that should return the next page against the value for Page.nextpage.getUrl(); it should return the same value.