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
Frank CarterFrank Carter 

apex test class insert help

Hello,

I need help with a test class.I have created an object related to opportunity, “billing detail”.
The result I want to reach is the creation of multiple child object, Billing details, according the number of months that I Have from the difference to “End of billing” and “Created date” divided for a number. The number is 2 if the billing is two-monthly, 1 if is monthly, 3 if is quarterly, 12 for annual. I have an after insert trigger that call an apex class(Helper).
Apex class:
public class Helper {
    public static void createBD(Billing_Detail__c bd){
        
        List <Billing_Detail__c> listBD = new List <Billing_Detail__c> ();
        Integer i=0;
        Integer K=0;
        
        if (bd.Billing_Period__c=='two-monthly') {
            k=2;
            Date myDate =bd.Monthly_Forecast__c;
        	
       
             
			
      if(((bd.Billing_Type__c=='FEE')||(bd.Billing_Type__c=='PPU'))&& bd.Billing_Period__c=='two-monthly'){
          
        i= myDate.monthsBetween(bd.End_of_Billing__c)/2;
      }
      
    
        for(Integer n =0; n<i-1; n++){//-1 mi serve altrimenti non considerando quella da interfaccia mi crea un'istanza in più
            if(i!=1){
            Billing_Detail__c newBd = new Billing_Detail__c ();
            
            newBd.Amount__c=bd.Amount__c;
            newBd.Billing_Date__c=bd.Billing_Date__c;
            newBd.Billing_Type__c=bd.Billing_Type__c;
            newBd.Billing_Status__c=bd.Billing_Status__c;
            newBd.Billing_Period__c= bd.Billing_Period__c;
            newBd.Product_Line__c=bd.Product_Line__c;
            newBd.Product__c=bd.Product__c;
            newBd.End_of_Billing__c=bd.End_of_Billing__c;     
            newBd.Billing_Detail__c=bd.Billing_Detail__c;
            newBd.CurrencyIsoCode=bd.CurrencyIsoCode;
            newBd.Monthly_Forecast__c= bd.Monthly_Forecast__c.addMonths(k);
            k+=2;
            listBD.add(newBd);
            }
        }
        insert listBD;
    }
        
       // ripeto le stesso operazioni di prima solo che qui si parla di trimestre quindi divido per 3
else if (bd.Billing_Period__c=='quarterly') {
            k=3;
                
        
         Date myDate =bd.Monthly_Forecast__c;

      
    	if (((bd.Billing_Type__c=='FEE')||(bd.Billing_Type__c=='PPU'))&& bd.Billing_Period__c=='quarterly'){
        i= myDate.monthsBetween(bd.End_of_Billing__c)/3;
        }
                
    
        for(Integer n =0; n<i-1; n++){
            if(i!=1){
            Billing_Detail__c newBd = new Billing_Detail__c ();
            
            newBd.Amount__c=bd.Amount__c;
            newBd.Billing_Date__c=bd.Billing_Date__c;
            newBd.Billing_Type__c=bd.Billing_Type__c;
            newBd.Billing_Status__c=bd.Billing_Status__c;
            newBd.Billing_Period__c= bd.Billing_Period__c;
            newBd.Product_Line__c=bd.Product_Line__c;
            newBd.Product__c=bd.Product__c;
            newBd.End_of_Billing__c=bd.End_of_Billing__c;     
            newBd.Billing_Detail__c=bd.Billing_Detail__c;
            newBd.CurrencyIsoCode=bd.CurrencyIsoCode;
            newBd.Monthly_Forecast__c= bd.Monthly_Forecast__c.addMonths(k);//parametro k per data scalata
            k+=3;
            listBD.add(newBd);
            }
        }
        insert listBD;
    }
else if (bd.Billing_Period__c=='annual') {
            k=12;

         Date myDate =bd.Monthly_Forecast__c;       
        
       
             

        if (((bd.Billing_Type__c=='FEE')||(bd.Billing_Type__c=='PPU'))&& bd.Billing_Period__c=='annual'){
        i= myDate.monthsBetween(bd.End_of_Billing__c)/12;
        }
        
    
        for(Integer n =0; n<i-1; n++){
            if(i!=1){
            Billing_Detail__c newBd = new Billing_Detail__c ();
            
            newBd.Amount__c=bd.Amount__c;
            newBd.Billing_Date__c=bd.Billing_Date__c;
            newBd.Billing_Type__c=bd.Billing_Type__c;
            newBd.Billing_Status__c=bd.Billing_Status__c;
            newBd.Billing_Period__c= bd.Billing_Period__c;
            newBd.Product_Line__c=bd.Product_Line__c;
            newBd.Product__c=bd.Product__c;
            newBd.End_of_Billing__c=bd.End_of_Billing__c;     
            newBd.Billing_Detail__c=bd.Billing_Detail__c;
            newBd.CurrencyIsoCode=bd.CurrencyIsoCode;
            newBd.Monthly_Forecast__c= bd.Monthly_Forecast__c.addMonths(k);
            k+=12;
            listBD.add(newBd);
            }
        }
        insert listBD;
    }
        else if (bd.Billing_Period__c=='monthly'){

           

            Date myDate =bd.Monthly_Forecast__c;
            
             if(((bd.Billing_Type__c=='FEE')||(bd.Billing_Type__c=='PPU'))&& bd.Billing_Period__c=='monthly'){
        i= myDate.monthsBetween(bd.End_of_Billing__c);
             System.debug('i='+i);
        }
             
            for(Integer n =0; n<i-1; n++){
            if(i!=1){
            Billing_Detail__c newBd = new Billing_Detail__c ();
            System.debug('n='+n);
            
            newBd.Amount__c=bd.Amount__c;
               System.debug('amount'+newBd.Amount__c); 
            newBd.Billing_Date__c=bd.Billing_Date__c;
            newBd.Billing_Type__c=bd.Billing_Type__c;
            newBd.Billing_Status__c=bd.Billing_Status__c;
            newBd.Billing_Period__c= bd.Billing_Period__c;
            newBd.Product_Line__c=bd.Product_Line__c;
            newBd.Product__c=bd.Product__c;
            newBd.End_of_Billing__c=bd.End_of_Billing__c;     
         	newBd.Billing_Detail__c=bd.Billing_Detail__c;
            newBd.CurrencyIsoCode=bd.CurrencyIsoCode;
            newBd.Monthly_Forecast__c= bd.Monthly_Forecast__c.addMonths(n+1);
                 System.debug('monthly forecast'+newBd.Monthly_Forecast__c);
            
            listBD.add(newBd);
                
            }
            
        }
        insert listBD;
        }
    
        }

}
Now I'm trying to create a test class.
@isTest public class testHelper {
@isTest static void testcreateBD(){

 // create the object in input of the class 

Helper Billing_Detail__c c= new Billing_Detail__c(); 
c.Amount__c= 100; c.Billing_Type__c='UNA TANTUM'; 
c.Billing_Status__c='Authorized for Billing'; 
c.Product_Line__c='Interactive Experience (iX)'; 
c.Product__c='Chat Delivery'; 
c.Monthly_Forecast__
c=Date.newInstance(2018, 7, 9); 
c.End_of_Billing__c=Date.newInstance(2018, 7, 9); 
c.Billing_Detail__c='test 1'; c.CurrencyIsoCode='€'; 

//call Helper class with createBD with c in input 
Helper.createBD(c); 
System.assert.Equals( ??? ); } }
but I don't understand how to continue.
I thought to put into "System.assert.Equals" the length of the listBD(class Helper - CreateBD method) but it doesn't recognize listBD in TestHelper.
Can anyone help me?

Thanks,
Frank



 
Best Answer chosen by Frank Carter
Steven NsubugaSteven Nsubuga
I have made some changes as well as added additional test methods.
@isTest public class testHelper {
    @isTest static void testFeeMonthly(){       
        
     // create the object in input of the class 
     Account acct = new Account(Name = 'Test Account');
     insert acct;
     
     Opportunity testOpportunity = new Opportunity(
            AccountID = acct.Id,
            Name = 'Test Opportunity',
            StageName = 'Needs Analysis',
            CloseDate = date.today().addDays(15)        
           
        );
        insert testOpportunity;

    Billing_Detail__c c= new Billing_Detail__c(); 
    c.Amount__c= 100;
    c.Billing_Type__c='FEE';
    c.Billing_Period__c='monthly';
    c.Billing_Status__c='Authorized for Billing'; 
    c.Product_Line__c='Interactive Experience (iX)'; 
    c.Product__c='Chat Delivery'; 
    c.Monthly_Forecast__c=Date.newInstance(2018, 7, 9); 
    c.End_of_Billing__c=Date.newInstance(2019, 7, 9); 
    c.Billing_Detail__c=testOpportunity.Id;

    //call Helper class with createBD with c in input 
    Helper.createBD(c);
    List <Billing_Detail__c> listBD = [SELECT Id FROM Billing_Detail__c];
    
    System.assert(listBD.size() > 1); 
    } 
    
    @isTest static void testPPUmonthly(){
        
        
    Account acct = new Account(Name = 'Test Account');
     insert acct;
     
     Opportunity testOpportunity = new Opportunity(
            AccountID = acct.Id,
            Name = 'Test Opportunity',
            StageName = 'Needs Analysis',
            CloseDate = date.today().addDays(15)        
           
        );
        insert testOpportunity;
        
    Billing_Detail__c c= new Billing_Detail__c(); 
    c.Amount__c= 100;
    c.Billing_Type__c='PPU';
    c.Billing_Period__c='monthly';
    c.Billing_Status__c='Authorized for Billing'; 
    c.Product_Line__c='Interactive Experience (iX)'; 
    c.Product__c='Chat Delivery'; 
    c.Monthly_Forecast__c=Date.newInstance(2018, 7, 9); 
    c.End_of_Billing__c=Date.newInstance(2019, 7, 9);
    c.Billing_Detail__c=testOpportunity.Id;


    //call Helper class with createBD with c in input 
    Helper.createBD(c);
    List <Billing_Detail__c> listBD = [SELECT Id FROM Billing_Detail__c ];
    
    System.assert(listBD.size() > 1); 
    }
    
    @isTest static void testFee2Monthly(){       
        

     // create the object in input of the class 
     Account acct = new Account(Name = 'Test Account');
     insert acct;
     
     Opportunity testOpportunity = new Opportunity(
            AccountID = acct.Id,
            Name = 'Test Opportunity',
            StageName = 'Needs Analysis',
            CloseDate = date.today().addDays(15)        
           
        );
        insert testOpportunity;

    Billing_Detail__c c= new Billing_Detail__c(); 
    c.Amount__c= 100;
    c.Billing_Type__c='FEE';
    c.Billing_Period__c='two-monthly';
    c.Billing_Status__c='Authorized for Billing'; 
    c.Product_Line__c='Interactive Experience (iX)'; 
    c.Product__c='Chat Delivery'; 
    c.Monthly_Forecast__c=Date.newInstance(2018, 7, 9); 
    c.End_of_Billing__c=Date.newInstance(2019, 7, 9); 
    c.Billing_Detail__c=testOpportunity.Id;

    //call Helper class with createBD with c in input 
    Helper.createBD(c);
    List <Billing_Detail__c> listBD = [SELECT Id FROM Billing_Detail__c];
    
    System.assert(listBD.size() > 1); 
    } 
    
    @isTest static void testFeeQuarterly(){       
        

     // create the object in input of the class 
     Account acct = new Account(Name = 'Test Account');
     insert acct;
     
     Opportunity testOpportunity = new Opportunity(
            AccountID = acct.Id,
            Name = 'Test Opportunity',
            StageName = 'Needs Analysis',
            CloseDate = date.today().addDays(15)        
           
        );
        insert testOpportunity;

    Billing_Detail__c c= new Billing_Detail__c(); 
    c.Amount__c= 100;
    c.Billing_Type__c='FEE';
    c.Billing_Period__c='quarterly';
    c.Billing_Status__c='Authorized for Billing'; 
    c.Product_Line__c='Interactive Experience (iX)'; 
    c.Product__c='Chat Delivery'; 
    c.Monthly_Forecast__c=Date.newInstance(2018, 7, 9); 
    c.End_of_Billing__c=Date.newInstance(2019, 7, 9); 
    c.Billing_Detail__c=testOpportunity.Id;

    //call Helper class with createBD with c in input 
    Helper.createBD(c);
    List <Billing_Detail__c> listBD = [SELECT Id FROM Billing_Detail__c];
    
    System.assert(listBD.size() > 1); 
    } 
    
    @isTest static void testFeeAnnually(){       
        

     // create the object in input of the class 
     Account acct = new Account(Name = 'Test Account');
     insert acct;
     
     Opportunity testOpportunity = new Opportunity(
            AccountID = acct.Id,
            Name = 'Test Opportunity',
            StageName = 'Needs Analysis',
            CloseDate = date.today().addDays(15)        
           
        );
        insert testOpportunity;

    Billing_Detail__c c= new Billing_Detail__c(); 
    c.Amount__c= 100;
    c.Billing_Type__c='FEE';
    c.Billing_Period__c='annual';
    c.Billing_Status__c='Authorized for Billing'; 
    c.Product_Line__c='Interactive Experience (iX)'; 
    c.Product__c='Chat Delivery'; 
    c.Monthly_Forecast__c=Date.newInstance(2018, 3, 9); 
    c.End_of_Billing__c=Date.newInstance(2025, 8, 9); 
    c.Billing_Detail__c=testOpportunity.Id;

    //call Helper class with createBD with c in input 
    Helper.createBD(c);
    List <Billing_Detail__c> listBD = [SELECT Id FROM Billing_Detail__c];
    
    System.assert(listBD.size() > 1); 
    } 
  
}

 

All Answers

Steven NsubugaSteven Nsubuga
@isTest public class testHelper {
	@isTest static void testcreateBD(){

	 // create the object in input of the class 

	Helper Billing_Detail__c c= new Billing_Detail__c(); 
	c.Amount__c= 100; c.Billing_Type__c='UNA TANTUM'; 
	c.Billing_Status__c='Authorized for Billing'; 
	c.Product_Line__c='Interactive Experience (iX)'; 
	c.Product__c='Chat Delivery'; 
	c.Monthly_Forecast__
	c=Date.newInstance(2018, 7, 9); 
	c.End_of_Billing__c=Date.newInstance(2018, 7, 9); 
	c.Billing_Detail__c='test 1'; c.CurrencyIsoCode='€'; 

	//call Helper class with createBD with c in input 
	Helper.createBD(c);
    List <Billing_Detail__c> listBD = [SELECT Id FROM Billing_Detail__c];
	
	System.assert(listBD.size() > 0); 
	} 
}

 
Frank CarterFrank Carter
I don't understand if how I set the apex class test have sense.
Steven NsubugaSteven Nsubuga
It checks that after the createBD method has run, then more than 1  Billing_Detail__c record exists. In addition to the initial Billing_Detail__c, other Billing_Detail__c records should exist. Let me edit the condition to show that more than 1 Billing_Detail__c must exist after the code runs.
@isTest public class testHelper {
	@isTest static void testcreateBD(){

	 // create the object in input of the class 

	Helper Billing_Detail__c c= new Billing_Detail__c(); 
	c.Amount__c= 100; c.Billing_Type__c='UNA TANTUM'; 
	c.Billing_Status__c='Authorized for Billing'; 
	c.Product_Line__c='Interactive Experience (iX)'; 
	c.Product__c='Chat Delivery'; 
	c.Monthly_Forecast__
	c=Date.newInstance(2018, 7, 9); 
	c.End_of_Billing__c=Date.newInstance(2018, 7, 9); 
	c.Billing_Detail__c='test 1'; c.CurrencyIsoCode='€'; 

	//call Helper class with createBD with c in input 
	Helper.createBD(c);
    List <Billing_Detail__c> listBD = [SELECT Id FROM Billing_Detail__c];
	
	System.assert(listBD.size() > 1); 
	} 
}

 
Frank CarterFrank Carter
I think only one should exist when Billing_Type__c is UNA TANTUM.
I change the code to have a listBD.size() > 1);
@isTest public class testHelper {
	@isTest static void testcreateBD(){

	 // create the object in input of the class 

	Billing_Detail__c c= new Billing_Detail__c(); 
	c.Amount__c= 100;
    c.Billing_Type__c='FEE';
    c.Billing_Period__c='monthly';
	c.Billing_Status__c='Authorized for Billing'; 
	c.Product_Line__c='Interactive Experience (iX)'; 
	c.Product__c='Chat Delivery'; 
	c.Monthly_Forecast__c=Date.newInstance(2018, 7, 9); 
	c.End_of_Billing__c=Date.newInstance(2019, 7, 9); 
	c.Billing_Detail__c='test 1';
    c.CurrencyIsoCode='€'; 

	//call Helper class with createBD with c in input 
	Helper.createBD(c);
    List <Billing_Detail__c> listBD = [SELECT Id FROM Billing_Detail__c];
	
	System.assert(listBD.size() > 1); 
	} 
}
but code coverage =0;
 
Frank CarterFrank Carter
can someone help me?
Steven NsubugaSteven Nsubuga
Hi Frank, we need more information. Can you track the execution of your code? I see a couple of System.debug statements in the Helper class.
You need to run the test and share your debug log here for us to scrutinize.  
Frank CarterFrank Carter
Thank you for your answer.
ok, I'll do it. but I've doubts.
1. the test class have sense? 
2. it is necessary to create first(in the test class) the account and opportunity related to the billing detail?
Steven NsubugaSteven Nsubuga
1. the test class have sense? 
Yes, it can definitely be improved but at the very least the Helper.createBD(c) method takes a Billing_Detail__c and creates 1 or more new Billing_Detail__c records, therefore it makes sense for the test method to check for the creation of new BD records. 

2. it is necessary to create first(in the test class) the account and opportunity related to the billing detail?
Only if the Billing_Detail__c cannot exist without account and opportunity, but that does not seem to be the case.

Lastly are you using this Helper class in a trigger? If so, share the trigger as well when you do post the execution log.
Frank CarterFrank Carter
trigger:
trigger bd on Billing_Detail__c (after insert) {
    if(CheckRecursive.firstRun){
        CheckRecursive.firstRun=false;
        for (Billing_Detail__c bd : Trigger.new) {
            if(trigger.size==1){
            Helper.createBD(trigger.new[0]);
            }
        }
    }
}
CheckRecursive class.
public class CheckRecursive { 
   public static boolean firstRun = true; 
}
last version of the test class:
@isTest public class testHelper {
	@isTest static void testFeeMonthly(){
      
	Opportunity opp=[Select id From Opportunity where id='0069E000007rexO'];
        
        

	 // create the object in input of the class 

	Billing_Detail__c c= new Billing_Detail__c(); 
	c.Amount__c= 100;
    c.Billing_Type__c='FEE';
    c.Billing_Period__c='monthly';
	c.Billing_Status__c='Authorized for Billing'; 
	c.Product_Line__c='Interactive Experience (iX)'; 
	c.Product__c='Chat Delivery'; 
	c.Monthly_Forecast__c=Date.newInstance(2018, 7, 9); 
	c.End_of_Billing__c=Date.newInstance(2019, 7, 9); 
	c.Billing_Detail__c=opp.Id;

	//call Helper class with createBD with c in input 
	Helper.createBD(c);
    List <Billing_Detail__c> listBD = [SELECT Id FROM Billing_Detail__c];
	
	System.assert(listBD.size() > 1); 
	} 
    
    @isTest static void testPPUmonthly(){
        
    Opportunity opp=[Select id From Opportunity where id='0069E000007rexO'];
        
    Billing_Detail__c c= new Billing_Detail__c(); 
	c.Amount__c= 100;
    c.Billing_Type__c='PPU';
    c.Billing_Period__c='monthly';
	c.Billing_Status__c='Authorized for Billing'; 
	c.Product_Line__c='Interactive Experience (iX)'; 
	c.Product__c='Chat Delivery'; 
	c.Monthly_Forecast__c=Date.newInstance(2018, 7, 9); 
	c.End_of_Billing__c=Date.newInstance(2019, 7, 9);
    c.Billing_Detail__c=opp.Id;


	//call Helper class with createBD with c in input 
	Helper.createBD(c);
    List <Billing_Detail__c> listBD = [SELECT Id FROM Billing_Detail__c ];
	
	System.assert(listBD.size() > 1); 
	} 
  
}

error:
System.QueryException: List has no rows for assignment to SObject
Class.testHelper.testFeeMonthly: line 4, column 1
Class.testHelper.testPPUmonthly: line 30, column 1


 
Steven NsubugaSteven Nsubuga
I have made some changes as well as added additional test methods.
@isTest public class testHelper {
    @isTest static void testFeeMonthly(){       
        
     // create the object in input of the class 
     Account acct = new Account(Name = 'Test Account');
     insert acct;
     
     Opportunity testOpportunity = new Opportunity(
            AccountID = acct.Id,
            Name = 'Test Opportunity',
            StageName = 'Needs Analysis',
            CloseDate = date.today().addDays(15)        
           
        );
        insert testOpportunity;

    Billing_Detail__c c= new Billing_Detail__c(); 
    c.Amount__c= 100;
    c.Billing_Type__c='FEE';
    c.Billing_Period__c='monthly';
    c.Billing_Status__c='Authorized for Billing'; 
    c.Product_Line__c='Interactive Experience (iX)'; 
    c.Product__c='Chat Delivery'; 
    c.Monthly_Forecast__c=Date.newInstance(2018, 7, 9); 
    c.End_of_Billing__c=Date.newInstance(2019, 7, 9); 
    c.Billing_Detail__c=testOpportunity.Id;

    //call Helper class with createBD with c in input 
    Helper.createBD(c);
    List <Billing_Detail__c> listBD = [SELECT Id FROM Billing_Detail__c];
    
    System.assert(listBD.size() > 1); 
    } 
    
    @isTest static void testPPUmonthly(){
        
        
    Account acct = new Account(Name = 'Test Account');
     insert acct;
     
     Opportunity testOpportunity = new Opportunity(
            AccountID = acct.Id,
            Name = 'Test Opportunity',
            StageName = 'Needs Analysis',
            CloseDate = date.today().addDays(15)        
           
        );
        insert testOpportunity;
        
    Billing_Detail__c c= new Billing_Detail__c(); 
    c.Amount__c= 100;
    c.Billing_Type__c='PPU';
    c.Billing_Period__c='monthly';
    c.Billing_Status__c='Authorized for Billing'; 
    c.Product_Line__c='Interactive Experience (iX)'; 
    c.Product__c='Chat Delivery'; 
    c.Monthly_Forecast__c=Date.newInstance(2018, 7, 9); 
    c.End_of_Billing__c=Date.newInstance(2019, 7, 9);
    c.Billing_Detail__c=testOpportunity.Id;


    //call Helper class with createBD with c in input 
    Helper.createBD(c);
    List <Billing_Detail__c> listBD = [SELECT Id FROM Billing_Detail__c ];
    
    System.assert(listBD.size() > 1); 
    }
    
    @isTest static void testFee2Monthly(){       
        

     // create the object in input of the class 
     Account acct = new Account(Name = 'Test Account');
     insert acct;
     
     Opportunity testOpportunity = new Opportunity(
            AccountID = acct.Id,
            Name = 'Test Opportunity',
            StageName = 'Needs Analysis',
            CloseDate = date.today().addDays(15)        
           
        );
        insert testOpportunity;

    Billing_Detail__c c= new Billing_Detail__c(); 
    c.Amount__c= 100;
    c.Billing_Type__c='FEE';
    c.Billing_Period__c='two-monthly';
    c.Billing_Status__c='Authorized for Billing'; 
    c.Product_Line__c='Interactive Experience (iX)'; 
    c.Product__c='Chat Delivery'; 
    c.Monthly_Forecast__c=Date.newInstance(2018, 7, 9); 
    c.End_of_Billing__c=Date.newInstance(2019, 7, 9); 
    c.Billing_Detail__c=testOpportunity.Id;

    //call Helper class with createBD with c in input 
    Helper.createBD(c);
    List <Billing_Detail__c> listBD = [SELECT Id FROM Billing_Detail__c];
    
    System.assert(listBD.size() > 1); 
    } 
    
    @isTest static void testFeeQuarterly(){       
        

     // create the object in input of the class 
     Account acct = new Account(Name = 'Test Account');
     insert acct;
     
     Opportunity testOpportunity = new Opportunity(
            AccountID = acct.Id,
            Name = 'Test Opportunity',
            StageName = 'Needs Analysis',
            CloseDate = date.today().addDays(15)        
           
        );
        insert testOpportunity;

    Billing_Detail__c c= new Billing_Detail__c(); 
    c.Amount__c= 100;
    c.Billing_Type__c='FEE';
    c.Billing_Period__c='quarterly';
    c.Billing_Status__c='Authorized for Billing'; 
    c.Product_Line__c='Interactive Experience (iX)'; 
    c.Product__c='Chat Delivery'; 
    c.Monthly_Forecast__c=Date.newInstance(2018, 7, 9); 
    c.End_of_Billing__c=Date.newInstance(2019, 7, 9); 
    c.Billing_Detail__c=testOpportunity.Id;

    //call Helper class with createBD with c in input 
    Helper.createBD(c);
    List <Billing_Detail__c> listBD = [SELECT Id FROM Billing_Detail__c];
    
    System.assert(listBD.size() > 1); 
    } 
    
    @isTest static void testFeeAnnually(){       
        

     // create the object in input of the class 
     Account acct = new Account(Name = 'Test Account');
     insert acct;
     
     Opportunity testOpportunity = new Opportunity(
            AccountID = acct.Id,
            Name = 'Test Opportunity',
            StageName = 'Needs Analysis',
            CloseDate = date.today().addDays(15)        
           
        );
        insert testOpportunity;

    Billing_Detail__c c= new Billing_Detail__c(); 
    c.Amount__c= 100;
    c.Billing_Type__c='FEE';
    c.Billing_Period__c='annual';
    c.Billing_Status__c='Authorized for Billing'; 
    c.Product_Line__c='Interactive Experience (iX)'; 
    c.Product__c='Chat Delivery'; 
    c.Monthly_Forecast__c=Date.newInstance(2018, 3, 9); 
    c.End_of_Billing__c=Date.newInstance(2025, 8, 9); 
    c.Billing_Detail__c=testOpportunity.Id;

    //call Helper class with createBD with c in input 
    Helper.createBD(c);
    List <Billing_Detail__c> listBD = [SELECT Id FROM Billing_Detail__c];
    
    System.assert(listBD.size() > 1); 
    } 
  
}

 
This was selected as the best answer