You need to sign in to do that
Don't have an account?
Unit Tests for Custom VisualForce Controllers: Setting ApexPages parameters
I cannot seem to find resources about how to set ApexPages parameters for unit tests.
I have a controller similar to:
public class MyCustomController {
public class visualForceException extends Exception {}
public MyCustomController() {
// if there is no 'id' parameter, throw error and return
if (ApexPages.currentPage().getParameters().get('id') == null) {
ApexPages.addMessages(new visualForceException('Error: No ID specified.'));
return;
}
// ... do other stuff here
}
}
Here, the constructor will check if there is an 'id' parameter in the current page.
My problem is... how do I set the ApexPages 'id' parameter in my TEST class?
ApexPages.CurrentPage().getParameters().put('ParamaterName', 'Value');
Use that before in the first part of you test method before you call the controller.
All Answers
ApexPages.CurrentPage().getParameters().put('ParamaterName', 'Value');
Use that before in the first part of you test method before you call the controller.
Ah, yes. I ended up finding that solution in this resource:
http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods
Thanks for the reply, Doug!