What do I assert in this test for a scheduled class?

This is my Scheduler class.

global class LeadSummary_Scheduler implements Schedulable{
   global void execute(SchedulableContext sc) 
       getCreatedLeadsSummary gcls = new getCreatedLeadsSummary();

The test coverage on this class was 0%. So I started writing a test for this class. Here is my test.

private class TestLeadSummarySchedClass {
static testmethod void test() {

        LeadSummary_Scheduler batchApex = new LeadSummary_Scheduler();

So now my question is what do I need to assert after Test.stopTest()?

Edit: Interestingly this test has covered the above class by 100%. Is this by design?


Abhi, scheduled APEX should be tested in a slightly different way.
Please refer to the testing section in this article which will show you how.


Basically the thing to note is that when you are testing scheduled APEX, you need to ensure that the scheduled method has been executed before you can check the results of your method.

Therefore as shown in the above example, you will need to use System.schedule and schedule a job within the Test.startTest() and Test.stopTest() methods.

You can also see an example of how the Assert statement has been used.

Source : Link , Question Author : abhi , Answer Author : Richard N

Leave a Comment