Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

Get the page reference using -

PageReference vfPageRef= Page.vfPageName; 

and set current PageReference for the controller. -

Test.setCurrentPage(vfPageRef);
share|improve this answer

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);
share|improve this answer

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 */

}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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