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
Eric.Goehring.ax954Eric.Goehring.ax954 

Need Test Coverage

How do I write a Test Class for:

 

public class ScheduleController {  
public Id Ins_Id {get;set;}  
public List<Schedule__c> thisInsertSch = new List<Schedule__c>();
public List<Schedule__c> getthisInsertSch() {        
thisInsertSch = [select id, Publication_Date__c, Ad_Discount_Pct__c from Schedule__c where Insertion_Order__c=:Ins_Id ORDER BY Publication_Date__c];       
return thisInsertSch; 
}
}
Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I think you need something like:

 

 

public static testMethod void testcontroller()
{
   // create an insertion order - probably needs fields but not
   // clear from the original post
   Insertion_Order__c testinsertion=new Insertion_Order__c();
   insert testinsertion;
    
   
   // create a test schedule
   Schedule__c testschedule=new Schedule__c( 
              Publication_Date__c=System.now(),
              Ad_Discount_Pct__c=0.2,
              Insertion_Order__c=testinsertion.id);

   
   ScheduleController controller=new ScheduleController();
   controller.ins_id=testinsertion.id;

   List<Schedule__c> scheds=controller.getthisInsertSch();
   System.assertEquals(scheds.size(), 1);
}

 

 

All Answers

bob_buzzardbob_buzzard

I think you need something like:

 

 

public static testMethod void testcontroller()
{
   // create an insertion order - probably needs fields but not
   // clear from the original post
   Insertion_Order__c testinsertion=new Insertion_Order__c();
   insert testinsertion;
    
   
   // create a test schedule
   Schedule__c testschedule=new Schedule__c( 
              Publication_Date__c=System.now(),
              Ad_Discount_Pct__c=0.2,
              Insertion_Order__c=testinsertion.id);

   
   ScheduleController controller=new ScheduleController();
   controller.ins_id=testinsertion.id;

   List<Schedule__c> scheds=controller.getthisInsertSch();
   System.assertEquals(scheds.size(), 1);
}

 

 

This was selected as the best answer
Eric.Goehring.ax954Eric.Goehring.ax954

Bob, you are the MAN! Thank you very much. This worked like a charm.