Ask Search:
Shruthi MNShruthi MN 

Test Case Error Help

@isTest

private class SearchCustomerBillTest

{

private static testMethod void BillingDetails() {

Credit_Card_Master_c cc_master = new Credit_Card_Master__c();

cc_master.Name = 'Edu_Diamond';

cc_master.Monthly_Card_Fees__c = 13;

cc_master.Card_Limit_c = '450000';

cc_master.Card_Type_c = 'Credit';

insert cc_master;

Customer_Details__c cust_det = new Customer_Details_c();

cust_det.Name = 'Test Customer';

cust_det.Email_Id__c = 'testcustomer@credit.com';

cust_det.Phone_Number__c = '22222222';

insert cust_det;

Customer_Details_c cust_det = new Customer_Details__c();
cust_det.Name = 'Test Customer';
cust_det. Email_Id_c = 'testcustorner@credit . corn';
 cust_det.Phone_Number_c = '22222222';
insert cust_det;
Customer_Credit_Junction__c crj = new Custorner_Credit_Junction__c();
crj.Credit_Card_Type_Master__c = cc_master.id ;
crj.Customer_Detail__c = cust_det.id;
insert cri;
Billing_Information__c bill = new Billing_Information_c();
bill.Bill_End_Date__c = Date.newlnstance(2819, 4, 30);
bill.Customer_Credit_Junction__c = crj.id;
insert bill;
test.startTest();
SearchCustomerBill search = new SearchCustomerBill();
search.CreditCardNumber = bill.Customer_Credit_Junction__c;
search.setCreditCardNumber(bill.Custorner_Credit_Junction__c);
search .getCreditCardNumber;
search.SearchBills();
search.getBillList();
 test.stopTest();
}
}
 
Best Answer chosen by Shruthi MN
Payal MittalPayal Mittal
@isTest
private class SearchCustomerBillTest
{  
	public static testMethod void BillingDetailstest(){
        Credit_Card_Master__c cc_master = new Credit_Card_Master__c();
        cc_master.Name = 'Edu_Diamond';
        cc_master.Monthly_Card_Fees__c = 13;
        cc_master.Card_Limit__c = 450000;
        cc_master.Card_Type__c = 'Credit';
        insert cc_master;

        Customer_Details__c cust_det = new Customer_Details__c();
        cust_det.Name = 'Test Customer';
        cust_det.Email__c = 'testcustomer@credit.com';
        cust_det.Phone_Number__c = '22222222';
        insert cust_det;

        /*Customer_Details__c cust_det1 = new Customer_Details__c();
        cust_det1.Name = 'Test Customer2';
        cust_det1. Email__c = 'testcustorner2@credit.com';
        cust_det1.Phone_Number__c = '22222211';
        insert cust_det1;*/
        
        Customer_Credit_Junction__c crj = new Customer_Credit_Junction__c();
        crj.Credit_Card_Type_Master__c = cc_master.id ;
        crj.Customer_Detail__c = cust_det.id;
        insert crj;
        
        Billing_Information__c bill = new Billing_Information__c();
        bill.Bill_End_Date__c = date.today();
        bill.Credit_Card_junction__c = crj.id;
        insert bill;
        
		//Test.startTest();
		SearchCustomerBill search = new SearchCustomerBill();
		//search.CreditCardNumber = bill.Customer_Credit_Junction__c;
		search.setCreditCardNumber(bill.Credit_Card_junction__c);
		search.getCreditCardNumber();
		search.SearchBills();
		search.getBillList();
		//Test.stopTest(); 
    }
}

All Answers

Prashant PandeyPrashant Pandey
What error are you getting?
Sajil EruvenkaiSajil Eruvenkai
Hi Shruthi,

Please post the error and the class to understand the lines covered.

Thanks
Payal MittalPayal Mittal
Hi Shruthi,

At many places i see usage of  '_c'. In Salesforce when you use custom object/fields, we have to append with '__c' .i.e. 2 underscores.
So try not to copy paste. Instead write the code by yourself.
As object names also seems to be wrong.
Payal MittalPayal Mittal
Try below code and if still it has errors, please post the errors as well:
@isTest

private class SearchCustomerBillTest

{

	private static testMethod void BillingDetails() {

		Credit_Card_Master__c cc_master = new Credit_Card_Master__c();
		cc_master.Name = 'Edu_Diamond';
		cc_master.Monthly_Card_Fees__c = 13;
		cc_master.Card_Limit__c = '450000';
		cc_master.Card_Type__c = 'Credit';
		insert cc_master;

		Customer_Details__c cust_det = new Customer_Details__c();
		cust_det.Name = 'Test Customer';
		cust_det.Email_Id__c = 'testcustomer@credit.com';
		cust_det.Phone_Number__c = '22222222';
		insert cust_det;

		Customer_Details__c cust_det1 = new Customer_Details__c();
		cust_det1.Name = 'Test Customer';
		cust_det1. Email_Id__c = 'testcustorner@credit.com';
		cust_det1.Phone_Number__c = '22222222';
		insert cust_det1;
		
		Customer_Credit_Junction__c crj = new Customer_Credit_Junction__c();
		crj.Credit_Card_Type_Master__c = cc_master.id ;
		crj.Customer_Detail__c = cust_det.id;
		insert crj;
		
		Billing_Information__c bill = new Billing_Information__c();
		bill.Bill_End_Date__c = Date.newlnstance(2819, 4, 30);
		bill.Customer_Credit_Junction__c = crj.id;
		insert bill;
		
		test.startTest();
			SearchCustomerBill search = new SearchCustomerBill();
			search.CreditCardNumber = bill.Customer_Credit_Junction__c;
			search.setCreditCardNumber(bill.Customer_Credit_Junction__c);
			search .getCreditCardNumber;
			search.SearchBills();
			search.getBillList();
		 test.stopTest();
	}
}

 
Shruthi MNShruthi MN
User-added image

@isTest

private class SearchCustomerBillTest

{

    private static testMethod void BillingDetails() {

        Credit_Card_Master__c cc_master = new Credit_Card_Master__c();
        cc_master.Name = 'Edu_Diamond';
        cc_master.Monthly_Card_Fees__c = 13;
        cc_master.Card_Limit__c = 4500;
        cc_master.Card_Type__c = 'Credit';
        insert cc_master;

        Customer_Details__c cust_det = new Customer_Details__c();
        cust_det.Name = 'Test Customer';
        cust_det.Email__c = 'testcustomer@credit.com';
        cust_det.Phone_Number__c = '22222222';
        insert cust_det;

        Customer_Details__c cust_det1 = new Customer_Details__c();
        cust_det1.Name = 'Test Customer';
        cust_det1.Email__c = 'testcustorner@credit.com';
        cust_det1.Phone_Number__c = '22222222';
        insert cust_det1;
        
        Customer_Credit_Junction__c crj = new Customer_Credit_Junction__c();
        crj.Credit_Card_Type_Master__c = cc_master.id ;
        crj.Customer_Detail__c = cust_det.id;
        insert crj;
        
        Billing_Information__c bill = new Billing_Information__c();
        bill.Bill_End_Date__c = Date.newlnstance(2019, 4, 30);
        bill.Credit_Card_junction__c = crj.id;
        insert bill;
        
        test.startTest();
            SearchCustomerBill search = new SearchCustomerBill();
            search.CreditCardNumber = bill.Credit_Card_junction__c;
            search.setCreditCardNumber(bill.Credit_Card_junction__c);
            search.getCreditCardNumber;
            search.SearchBills();
            search.getBillList();
         test.stopTest();
    }
}
 
Payal MittalPayal Mittal
@isTest

private class SearchCustomerBillTest

{

	private static testMethod void BillingDetails() {

		Credit_Card_Master__c cc_master = new Credit_Card_Master__c();
		cc_master.Name = 'Edu_Diamond';
		cc_master.Monthly_Card_Fees__c = 13;
		cc_master.Card_Limit__c = '450000';
		cc_master.Card_Type__c = 'Credit';
		insert cc_master;

		Customer_Details__c cust_det = new Customer_Details__c();
		cust_det.Name = 'Test Customer';
		cust_det.Email_Id__c = 'testcustomer@credit.com';
		cust_det.Phone_Number__c = '22222222';
		insert cust_det;

		Customer_Details__c cust_det1 = new Customer_Details__c();
		cust_det1.Name = 'Test Customer';
		cust_det1. Email_Id__c = 'testcustorner@credit.com';
		cust_det1.Phone_Number__c = '22222222';
		insert cust_det1;
		
		Customer_Credit_Junction__c crj = new Customer_Credit_Junction__c();
		crj.Credit_Card_Type_Master__c = cc_master.id ;
		crj.Customer_Detail__c = cust_det.id;
		insert crj;
		
		Billing_Information__c bill = new Billing_Information__c();
		bill.Bill_End_Date__c = today();
		bill.Customer_Credit_Junction__c = crj.id;
		insert bill;
		
		test.starttest();
			SearchCustomerBill search = new SearchCustomerBill();
			//search.CreditCardNumber = bill.Customer_Credit_Junction__c;
			search.setCreditCardNumber(bill.Customer_Credit_Junction__c);
			search.getCreditCardNumber();
			search.SearchBills();
			search.getBillList();
		 test.stoptest();
	}
}

 
Shruthi MNShruthi MN
User-added image
Shruthi MNShruthi MN
User-added image
Payal MittalPayal Mittal
Hi Shruthi,

Check the object names are correct or not:
 
@isTest

private class SearchCustomerBillTest

{

	private static testMethod void BillingDetails() {

		Credit_Card_Master__c cc_master = new Credit_Card_Master__c();
		cc_master.Name = 'Edu_Diamond';
		cc_master.Monthly_Card_Fees__c = 13;
		cc_master.Card_Limit__c = '450000';
		cc_master.Card_Type__c = 'Credit';
		insert cc_master;

		Customer_Details__c cust_det = new Customer_Details__c();
		cust_det.Name = 'Test Customer';
		cust_det.Email_Id__c = 'testcustomer@credit.com';
		cust_det.Phone_Number__c = '22222222';
		insert cust_det;

		Customer_Details__c cust_det1 = new Customer_Details__c();
		cust_det1.Name = 'Test Customer';
		cust_det1. Email_Id__c = 'testcustorner@credit.com';
		cust_det1.Phone_Number__c = '22222222';
		insert cust_det1;
		
		Credit_Card_Junction__c crj = new Credit_Card_Junction__c();
		crj.Credit_Card_Type_Master__c = cc_master.id ;
		crj.Customer_Detail__c = cust_det.id;
		insert crj;
		
		Billing_Information__c bill = new Billing_Information__c();
		bill.Bill_End_Date__c = date.today();
		bill.Customer_Credit_Junction__c = crj.id;
		insert bill;
		
		test.starttest();
			SearchCustomerBill search = new SearchCustomerBill();
			//search.CreditCardNumber = bill.Customer_Credit_Junction__c;
			search.setCreditCardNumber(bill.Customer_Credit_Junction__c);
			search.getCreditCardNumber();
			search.SearchBills();
			search.getBillList();
		 test.stoptest();
	}
}

 
Shruthi MNShruthi MN
I have chaged the object apis according to the system.

@isTest

private class SearchCustomerBillTest

{

    private static testMethod void BillingDetails() {

        Credit_Card_Master__c cc_master = new Credit_Card_Master__c();
        cc_master.Name = 'Edu_Diamond';
        cc_master.Monthly_Card_Fees__c = 13;
        cc_master.Card_Limit__c = '450000';
        cc_master.Card_Type__c = 'Credit';
        insert cc_master;

        Customer_Details__c cust_det = new Customer_Details__c();
        cust_det.Name = 'Test Customer';
        cust_det.Email__c = 'testcustomer@credit.com';
        cust_det.Phone_Number__c = '22222222';
        insert cust_det;

        Customer_Details__c cust_det1 = new Customer_Details__c();
        cust_det1.Name = 'Test Customer';
        cust_det1. Email__c = 'testcustorner@credit.com';
        cust_det1.Phone_Number__c = '22222222';
        insert cust_det1;
        
        Customer_Credit_Junction__c crj = new Customer_Credit_Junction__c();
        crj.Credit_Card_Type_Master__c = cc_master.id ;
        crj.Customer_Detail__c = cust_det.id;
        insert crj;
        
        Billing_Information__c bill = new Billing_Information__c();
        bill.Bill_End_Date__c = date.today();
        bill.Credit_Card_junction__c = crj.id;
        insert bill;
        
        test.starttest();
            SearchCustomerBill search = new SearchCustomerBill();
            //search.CreditCardNumber = bill.Customer_Credit_Junction__c;
            search.setCreditCardNumber(bill.Credit_Card_junction__c);
            search.getCreditCardNumber();
            search.SearchBills();
            search.getBillList();
         test.stoptest();
    }
}

User-added image
Shruthi MNShruthi MN
User-added image

now Im am getting only 4 errors
Shruthi MNShruthi MN
User-added image
Payal MittalPayal Mittal
@isTest
private class SearchCustomerBillTest
{
    static testMethod void BillingDetails() {
        Credit_Card_Master__c cc_master = new Credit_Card_Master__c();
        cc_master.Name = 'Edu_Diamond';
        cc_master.Monthly_Card_Fees__c = 13;
        cc_master.Card_Limit__c = 450000;
        cc_master.Card_Type__c = 'Credit';
        insert cc_master;

        Customer_Details__c cust_det = new Customer_Details__c();
        cust_det.Name = 'Test Customer';
        cust_det.Email__c = 'testcustomer@credit.com';
        cust_det.Phone_Number__c = '22222222';
        insert cust_det;

        Customer_Details__c cust_det1 = new Customer_Details__c();
        cust_det1.Name = 'Test Customer2';
        cust_det1. Email__c = 'testcustorner2@credit.com';
        cust_det1.Phone_Number__c = '22222211';
        insert cust_det1;
        
        Customer_Credit_Junction__c crj = new Customer_Credit_Junction__c();
        crj.Credit_Card_Type_Master__c = cc_master.id ;
        crj.Customer_Detail__c = cust_det.id;
        insert crj;
        
        Billing_Information__c bill = new Billing_Information__c();
        bill.Bill_End_Date__c = date.today();
        bill.Credit_Card_junction__c = crj.id;
        insert bill;
        
        Test.startTest();
        SearchCustomerBill search = new SearchCustomerBill();
        //search.CreditCardNumber = bill.Customer_Credit_Junction__c;
        search.setCreditCardNumber(bill.Credit_Card_junction__c);
        search.getCreditCardNumber();
        search.SearchBills();
        search.getBillList();
        Test.stopTest(); 
    }
}
Shruthi MNShruthi MN
User-added image
Payal MittalPayal Mittal
@isTest
private class SearchCustomerBillTest
{  
	public static testMethod void BillingDetailstest(){
        Credit_Card_Master__c cc_master = new Credit_Card_Master__c();
        cc_master.Name = 'Edu_Diamond';
        cc_master.Monthly_Card_Fees__c = 13;
        cc_master.Card_Limit__c = 450000;
        cc_master.Card_Type__c = 'Credit';
        insert cc_master;

        Customer_Details__c cust_det = new Customer_Details__c();
        cust_det.Name = 'Test Customer';
        cust_det.Email__c = 'testcustomer@credit.com';
        cust_det.Phone_Number__c = '22222222';
        insert cust_det;

        /*Customer_Details__c cust_det1 = new Customer_Details__c();
        cust_det1.Name = 'Test Customer2';
        cust_det1. Email__c = 'testcustorner2@credit.com';
        cust_det1.Phone_Number__c = '22222211';
        insert cust_det1;*/
        
        Customer_Credit_Junction__c crj = new Customer_Credit_Junction__c();
        crj.Credit_Card_Type_Master__c = cc_master.id ;
        crj.Customer_Detail__c = cust_det.id;
        insert crj;
        
        Billing_Information__c bill = new Billing_Information__c();
        bill.Bill_End_Date__c = date.today();
        bill.Credit_Card_junction__c = crj.id;
        insert bill;
        
		//Test.startTest();
		SearchCustomerBill search = new SearchCustomerBill();
		//search.CreditCardNumber = bill.Customer_Credit_Junction__c;
		search.setCreditCardNumber(bill.Credit_Card_junction__c);
		search.getCreditCardNumber();
		search.SearchBills();
		search.getBillList();
		//Test.stopTest(); 
    }
}
This was selected as the best answer
Shruthi MNShruthi MN
Thanks a ton its working :)