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
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityI'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
Get the page reference using -
PageReference vfPageRef= Page.vfPageName;
and set current PageReference for the controller. -
Test.setCurrentPage(vfPageRef);
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);
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 */ }