You need to sign in to do that
Don't have an account?
krishnag
help with test class
hi can anybody help me in writing test class for this controller. I need just a start to finish it.I am new to this test classes creation.
public with sharing class gusignup { 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; } public Boolean echeck { get; set; } public String rpwd { get; set; } public String pwd { get; set; } } 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 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; } }
http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods
Go through above URL.
thanks gopi i have gone through that before what i am thinking can we do that as creating a list because if u see my page has i have 20 field.So i need to write 20 get and set methods.so i am thinking is there any other way to avoid that.
I dot know any other better way but follow below points that will helpful
1.Create a test method in the class
2.CReate objects instances used in the class
3.Access method using object instances.
4.pass positive,negative,null values
you have some SOQL in yours code
send some dummy date to the objects and write the queries will work.yours code is very simple it not a mater writing 20 methods in a test method.
If you got any better idea update us.first try to post some code based on initial procedure.
thanks gopi i will definitely try this procedure.
Here is some sample code that will help you
I have method
xyz(String a)
{
}
test method()
{
object instance v;
v.xyz('abc');
v.xyz(123);
v.xyz(null);
here theree test case i wrote just try it let us know,
Thanks
hi i have written a test class for the above controller and i am geeting the error like
can anybody debug this
The error is due to the incorrect way of assigning value in fname. If there is a set function with name “fname” then you can assign value like this. If fname is a variable then you have to assign value as “controller.fname='abc'”.
Hope this helps.
hi pradeep i hade that correction and it got saved.When i run the test its giving me test failure
message saying
Class.gusignupTests.myUnitTest: line 30, column 22 External entry point
First insert some data into the table and query it.When you doiing any data base operation put it in try and catch block.
hi gopi the insertion of data is taken care by psignup method right which i have reffered in the test class.