+ Start a Discussion
RahulRahul 

Hi Friends, Please help me with the test class for this class

public class Bucket1controller {

public Bucket1__c buck1 = new Bucket1__c();

public Bucket1__c getbuck1(){


return buck1;
}

    public Bucket1controller(ApexPages.StandardController controller) {

    }

public pageReference Bucket1form2(){


return Page.Bucket1form2page;
}

public PageReference Saveall(){
Bucket1__c b = new Bucket1__c();
b.Aadhar_Number__c =buck1.Aadhar_Number__c;
b.CBIL__c =buck1.CBIL__c;

b.PAN_Number__c=buck1.PAN_Number__c;
b.Start_Date_and_TimeStamp__c = buck1.Start_Date_and_TimeStamp__c;
b.Accomodation_Type__c= buck1.Accomodation_Type__c;
b.Already_have_a_Loan__c =buck1.Already_have_a_Loan__c;
b.Borrower_Name__c=buck1.Borrower_Name__c;
b.Company_Name__c = buck1.Company_Name__c;
b.Company_Type__c = buck1.Company_Type__c;
b.Credit_card_holder__c = buck1.Credit_card_holder__c;
b.Date_of_birth__c  = buck1.Date_of_birth__c;

b.Eligibility_Check__c = buck1.Eligibility_Check__c;
b.Email__c=buck1.Email__c;
b.Full_Residential_Address__c = buck1.Full_Residential_Address__c;

b.Hoapital_clinic__c = buck1.Hoapital_clinic__c;

b.Last_Month_Salary__c = buck1.Last_Month_Salary__c;

b.Loan_Amount_Eligible__c = buck1.Loan_Amount_Eligible__c;
b.Loan_Amount__c = buck1.Loan_Amount__c;

b.Obligation_Amount__c = buck1.Obligation_Amount__c;
b.Phone_number__c = buck1.Phone_number__c;
b.Scheme__c =buck1.Scheme__c;
b.Treatment__c =buck1.Treatment__c;

insert b;

return Page.savedsuccessfully;
}
}
pconpcon
Since writing a test class to cover all of the facets of this class is not something that anyone on here will do for you, I can give you some pointers and hopefully get you started.  I would recommend that you do some reading on testing [1] [2] [3] [4] to get a better understanding.  Each of your individual tests should only tests one specific portion of you class (ie a constructor test, sendEmail test, contactSelected test, etc).  You should also have both a postitive (everything works perfectly) and a negative (things are not right) test.

Each test should follow the following structure:
     Setup of test data. This includes creation of any data needed by your class.  Account, Contacts etc
     Starting the test. This is calling Test.startTest() to reset the governor limits
     Calling your class / method
     Stopping the test.This is calling Test.stopTest() to reset the governor limits and allow for any async jobs to finish
     Asserting that your changes have worked
          If you have inserted/updated/deleted data, you need to query for the updates
          Run System.assert, System.assertEquals, System.assertNotEquals to verify that you got the correct data back

If you have any specific problems with your tests, feel free to create a new post with the part of the class you are trying to test and your current test method, and you will more likely get a better response then asking for someone to essentially write an entire test class for you.

[1] http://www.sfdc99.com/2013/05/14/how-to-write-a-test-class/
[2] http://pcon.github.io/presentations/testing/
[3] http://blog.deadlypenguin.com/blog/2014/07/23/intro-to-apex-auto-converting-leads-in-a-trigger/
[4] http://blog.deadlypenguin.com/blog/testing/strategies/