You need to sign in to do that
Don't have an account?
kcharubin
Testing Controller Extension for Visualforce Page
Hello
I've recently been writting a few basic controllers for some visualforce pages, and of course now need to test them. Problem is I don't really know how. Normally you know you'd instantiate the class, pass data to the methods, and assert against the results right? With this controller I dont know what to test against.
It would be great if someone could help me write a test calss for this
public class MyLeadsController { public List<Consumer_Leads__c> unassignedLeads {get; set;} public List<Consumer_Leads__c> allLeads {get; set;} public String leadCenter {get; set;} public MyLeadsController(ApexPages.StandardController controller) { leadCenter = ApexPages.currentPage().getParameters().get('lc'); this.allLeads = [select id, First_Name__c, Last_Name__c, State__c, Lead_Request__c, IFP_Producer_Receiving_the_Lead__c, Lead_Center__c from Consumer_Leads__c where Lead_Center__c = :leadCenter AND IFP_Producer_Receiving_the_Lead__c != '' order by id]; this.unassignedLeads = [select id, First_Name__c, Last_Name__c, State__c, Lead_Request__c, IFP_Producer_Receiving_the_Lead__c, Lead_Center__c from Consumer_Leads__c where Lead_Center__c = :leadCenter AND IFP_Producer_Receiving_the_Lead__c = '' order by id]; } public PageReference Save(){ update allLeads; update unassignedLeads; return null; } public PageReference Back(){ return new PageReference('/'+leadCenter); } }
Hi,
Below is sample code for your Test class.
Test Class:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
All Answers
Hi,
Below is sample code for your Test class.
Test Class:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
Thanks for the quick help. I modified it a little since I had some validation rules in place on Consumer_Leads__c.
I thought that in testMethod there needs to be System.assertEquals() and such.