+ Start a Discussion

Test class for scheduler class

Can some one please tell me how to write a Unit test class for the scheduler class below please.

Should i seperate class or can i write it in the same class with @IsTest notation. 



global class HF_Survey_OneMonth Implements Schedulable 
    global void execute(SchedulableContext sc)
    public void SendSurvey()
         // Get the most recently created config object.
         Config_Object__c config = [Select HFSurveyCode__c, Survey_Date__C, SOQL_Query__C from Config_Object__C 
                                    where Name ='HostFamily_Survey'];
         List<Opportunity> oppList = Database.query(config.SOQL_Query__c);
             List<Account> accList = new List<Account>();             
                   for(Opportunity opp:oppList)
                        if(opp.AccountId!= null)
                          Account acc = opp.Account;
                          if(acc.Survey_Code__c != String.valueOf(config.HFSurveyCode__c) || acc.Survey_Opp_Id__c != opp.Id)
                             string oppcode= opp.Id;
                             acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c); 
                             acc.Survey_Dt__c = config.Survey_Date__c;
                             acc.Survey_Opp_Id__c = oppcode.subString(0,15);
                update accList;  





Take a look at the followind documentation:



You can assert both the timing and the behavior.