You need to sign in to do that
Don't have an account?

Help with Test Method
I need help with writing a test method for a class that creates opens a Visualforce page with predetermined parameters. I have no idea where to begin if anyone can steer me in the right direction.
Here is the class...how do I write the method to test this?
public class psuNewCurrency { private final Participant_ID_Request__c request; private final Participant_ID__c objParticipant_Id; public String Participant_ID; public String Participant_ID_id; public String Request_ID; public String Request_Name; public String Record_Type; public psuNewCurrency(ApexPages.StandardController controller) { this.objParticipant_Id=[select Id, Name, Participant_ID_Generation__c from Participant_ID__c where Name=:System.CurrentPageReference().getParameters().get('CF00NS0000000O8dw')]; Participant_ID = System.CurrentPageReference().getParameters().get('CF00NS0000000O8dw'); Record_Type = System.CurrentPageReference().getParameters().get('RecordType'); Participant_ID_id = objParticipant_Id.Id; Request_ID = objParticipant_Id.Participant_ID_Generation__c; this.request=[select Id, Name from Participant_ID_Request__c where Id= :Request_ID ]; Request_Name = request.Name; } public Pagereference pageredir() { Pagereference newpage = new Pagereference ('/a0O/e?CF00NS0000000O8dw='+ Participant_ID +'&CF00NS0000000O8dw_lkid='+ Participant_ID_id +'&CF00NS0000000OAKq_lkid='+ Request_ID +'&CF00NS0000000OAKq='+ Request_Name +'&retURL='+ Participant_ID_id +'&RecordType='+ Record_Type +'&_CONFIRMATIONTOKEN=fzXMPMYOtRvbVHrmy6.3rdbroMrAH.pxVXb2iB71kL.oPdjgcmNKyWCeyGwgB68fQ7wBH_Zv5wDZyDMNz1NAt562.Ll8FVIhhjSmAuY6c9d8a2SLLWoZlctxQxROV.l7RHe32ME9Xr9XLz2y3aX7UmhlCYEe4RPZiluYf979pzFIyH3l' +'&cancelURL='+ Participant_ID_id +'&ent=01IS00000008Xhj' //Currency Relationship Object +'&nooverride=1'); return newpage; } }
If that's the whole class then your method needs to set some parameters in the request:
instantiate the class:
Then call the method on the class:
And finally you need to assert that the url and params are correct:
Now a couple of things to know here. I'm assuming that what's going on here is that you've overridden the new action for your custom object with a Visualforce page that uses this controller extension and binds the page component's action attribute to the pageredir() method. If so, then the stuff you are doing in your constructor to sniff request parameters is unnecessary.
The extension model required here is there for a reason, from the standardcontroller you can get a typed sobject for you to work with that includes defaulted values that are set by salesforce.com params. So in your case the constructor would look like this:
As for what you are doing in the redirection method yourself you need to recognize that you are programming against observed but not supported behavior. There is no guarantee any release of salesforce.com won't change how we name or process any of the parameters you are setting in the pageredir() method. The supported approach is to just present a form with this Visualforce page rather than use it to redirect. Yes this means you lose the page layout editor customization of the new form but it's the only way to guarantee against backwards compatibility issues you are subject to with this approach. Proceed as you must but do so with caution.
Andrew, this was absolutely marvelous! Here is my new code:
Class
Test
However, when I run the test, my assertion fails when I get the expected result (001)
Am I doing something wrong here?