function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RahulRahul 

Hello Friends, I have written Test class for this class but getting less code coverage. I have passed the values for every field.Need your Help

Test CLass :-

@istest
public class bucket1controllertest{

public static testmethod void metd1(){
Bucket1__c b = new Bucket1__c();
b.Aadhar_Number__c ='jcshusd66';
b.CBIL__c ='77567';
b.PAN_Number__c='hshshbhj678';
//b.Start_Date_and_TimeStamp__c =Now();
b.Accomodation_Type__c='own' ;
b.Already_have_a_Loan__c ='No';
b.Borrower_Name__c='jkcndjd';
b.Company_Name__c = 'abc';
b.Company_Type__c = 'jsdnjd';
b.Credit_card_holder__c ='Yes';
//b.Date_of_birth__c  = '1/08/1995';
b.Eligibility_Check__c = true;
b.Email__c='testr@gmail.com';
b.Full_Residential_Address__c = 'hdyh khskfh khsd kuhsukds hkdsdb';
b.Hoapital_clinic__c ='hbdc';
b.Last_Month_Salary__c = 67557;
b.Loan_Amount_Eligible__c = 600000;
b.Loan_Amount__c = 900000;
b.Obligation_Amount__c = 1000000;
b.Phone_number__c = '678767876';
b.Scheme__c ='hjgjdgsjdh';
b.Treatment__c ='jdnd';
insert b;
}
}

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;
}

}
Best Answer chosen by Rahul
Ramesh DRamesh D
ok try this
@istest
public class bucket1controllertest{
    
    public static testmethod void metd1(){
        Bucket1__c b = new Bucket1__c();
        b.Aadhar_Number__c ='jcshusd66';
        b.CBIL__c ='77567';
        b.PAN_Number__c='hshshbhj678';
        //b.Start_Date_and_TimeStamp__c =Now();
        b.Accomodation_Type__c='own' ;
        b.Already_have_a_Loan__c ='No';
        b.Borrower_Name__c='jkcndjd';
        b.Company_Name__c = 'abc';
        b.Company_Type__c = 'jsdnjd';
        b.Credit_card_holder__c ='Yes';
        //b.Date_of_birth__c  = '1/08/1995';
        b.Eligibility_Check__c = true;
        b.Email__c='testr@gmail.com';
        b.Full_Residential_Address__c = 'hdyh khskfh khsd kuhsukds hkdsdb';
        b.Hoapital_clinic__c ='hbdc';
        b.Last_Month_Salary__c = 67557;
        b.Loan_Amount_Eligible__c = 600000;
        b.Loan_Amount__c = 900000;
        b.Obligation_Amount__c = 1000000;
        b.Phone_number__c = '678767876';
        b.Scheme__c ='hjgjdgsjdh';
        b.Treatment__c ='jdnd';
        insert b;       
        ApexPages.StandardController sc = new ApexPages.StandardController(b);
        Bucket1controller bc=new Bucket1controller(sc);
        bc.Saveall();
        bc.Bucket1form2();
    }
}

Thanks
Ramesh​​​​​​​

All Answers

Ramesh DRamesh D
@Sumit,
Can you please post test coverage screenshot, so we can see what lines are not coverd?

Thanks
RahulRahul
Hi Ramesh, I was getting 4% code coverage, but when I refreshed it now it shows as 0%. 
Ramesh DRamesh D
run the test class go to your controller class and select all test you will be able to see what lines covered and what not..
RahulRahul
After running the Test class, when I refresh the Apex class the code coverage is 0% now. It means something in this Test class is not working
Ramesh DRamesh D
ok try this
@istest
public class bucket1controllertest{
    
    public static testmethod void metd1(){
        Bucket1__c b = new Bucket1__c();
        b.Aadhar_Number__c ='jcshusd66';
        b.CBIL__c ='77567';
        b.PAN_Number__c='hshshbhj678';
        //b.Start_Date_and_TimeStamp__c =Now();
        b.Accomodation_Type__c='own' ;
        b.Already_have_a_Loan__c ='No';
        b.Borrower_Name__c='jkcndjd';
        b.Company_Name__c = 'abc';
        b.Company_Type__c = 'jsdnjd';
        b.Credit_card_holder__c ='Yes';
        //b.Date_of_birth__c  = '1/08/1995';
        b.Eligibility_Check__c = true;
        b.Email__c='testr@gmail.com';
        b.Full_Residential_Address__c = 'hdyh khskfh khsd kuhsukds hkdsdb';
        b.Hoapital_clinic__c ='hbdc';
        b.Last_Month_Salary__c = 67557;
        b.Loan_Amount_Eligible__c = 600000;
        b.Loan_Amount__c = 900000;
        b.Obligation_Amount__c = 1000000;
        b.Phone_number__c = '678767876';
        b.Scheme__c ='hjgjdgsjdh';
        b.Treatment__c ='jdnd';
        insert b;       
        ApexPages.StandardController sc = new ApexPages.StandardController(b);
        Bucket1controller bc=new Bucket1controller(sc);
        bc.Saveall();
        bc.Bucket1form2();
    }
}

Thanks
Ramesh​​​​​​​
This was selected as the best answer
RahulRahul
Iam very Thankful to you :)