0

I've created a apex class in which I used current page name for some purpose.Now while creating a Test class for that I need to create a virtual visual Force page.So how to create that page in test class.

Thanks

2

Get the page reference using -

PageReference vfPageRef= Page.vfPageName; 

and set current PageReference for the controller. -

Test.setCurrentPage(vfPageRef);
0

You set the current page ref as the page you are testing.

http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_error_handling.htm

PageReference pageRef = Page.success; 
Test.setCurrentPage(pageRef);
0

Do you need to write your test code on current page? set current page using following code..

public static testMethod void testMyController()
 {      

PageReference pageRef = Page.YourPageName;

Test.setCurrentPage(pageRef);

/* Your code for test coverage */

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.