You need to sign in to do that
Don't have an account?
krishnag
test class for a controller
hi,
i am new to this test classes concept. Can anybody give an example for writing a test class for a controller.
public PageReference psignup() { emailerror=false; emailacept=false; List<guestuser__c> ldtls=[select Id from guestuser__c where Email__c=:email]; if(ldtls.size()>0) { emailerror=true; emailacept=false; //uid exist } else { if(pwd==rpwd) { emailerror=false; emailacept=false; guestuser__c gu=new guestuser__c(); gu.First_Name__c=fname; gu.Password__c=pwd; gu.Email__c=email; gu.Title__c = job; gu.Email_Optout__c = echeck; gu.Last_Name__c = lname; gu.Company__c = comp; gu.Street__c = street; gu.State__c = state; gu.City__c = city; gu.Country__c = ctry; gu.Zipcode__c = zip; Lead ld=new Lead(); ld.FirstName =fname; ld.LastName=lname; ld.Company=comp; ld.Street=street; ld.State=state; ld.city=city; ld.PostalCode=zip; ld.country=ctry; ld.Title=job; ld.Email=email; ld.HasOptedOutOfEmail=echeck; try{ insert ld; insert gu; Pagereference pageref=new Pagereference('/apex/thankq'); pageref.setRedirect(true); return pageref; } catch(Exception e) { system.debug(e); } } else { ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.WARNING, 'PASSWORD MISS-MATCH'); ApexPages.addMessage(myMsg); } } return null; } public Boolean echeck { get; set; } public String rpwd { get; set; } public String pwd { get; set; } public void checkavlble() { String lusername= Apexpages.currentPage().getParameters().get('mail'); List<guestuser__c> chkldtls=[select Id from guestuser__c where Email__c=:email]; if(chkldtls.size()>0) { emailerror=true; emailacept=false; } else { //try another emailerror=false; emailacept=true; } } public Boolean emailacept { get; set; } public Boolean emailerror { get; set; } public String email { get; set; } public String job { get; set; } public String ctry { get; set; } public String zip { get; set; } public String state { get; set; } public String city { get; set; } public String street { get; set; } public String comp { get; set; } public String lname { get; set; } public String fname { get; set; } }
i need to write the test class for this controller to deploy the page.can anybody help me with an example.
Try setting your values like:
controller.fname = 'abc';
instead of like:
controller.fname('abc');
Jeff Douglas
Appirio, Inc.
http://blog.jeffdouglas.com
Author: The Salesforce Handbook
All Answers
Check out the following blog post:
Testing Salesforce.com Controller Extensions
Jeff Douglas
Appirio, Inc.
http://blog.jeffdouglas.com
Author: The Salesforce Handbook
hi i wrote the test class for the above controller and i am getting the error.
Error: Compile Error: Method does not exist or incorrect signature: [gusignup].fname(String) at line 13 column 4
Try setting your values like:
controller.fname = 'abc';
instead of like:
controller.fname('abc');
Jeff Douglas
Appirio, Inc.
http://blog.jeffdouglas.com
Author: The Salesforce Handbook
thanks its working jeff