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
EtienneCoutantEtienneCoutant 

How to write test for Apex Scheduler

Hi,

 

I have created a Class that implements the Schedulable interface for a batch Apex class called batchable:

 

 

global class scheduledBatchable implements Schedulable{ global void execute(SchedulableContext sc) { batchable b = new batchable(); database.executebatch(b); } }

 

 Now I am not sure how I can write my test class... Can i call execute() ? What should be the SchedulableContext?

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
tmatthiesentmatthiesen

Take a look at the docs: 

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_scheduler.htm?SearchType=Stem

 

Per the example, you can validate the cron expression by validating the next fire time.  Similar to Batch and @future, you can invoke the scheduler after Test.startTest() and assert the execute behavior after Test.stopTest().

 

 

Message Edited by tmatthiesen on 03-08-2010 09:29 AM