Created
December 15, 2011 22:46
-
-
Save evandonovan/1483308 to your computer and use it in GitHub Desktop.
Test for my scheduled Apex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
private class TestCityvisionScheduledTasks { | |
// just tests whether the scheduled classes run. | |
static testMethod void testRunsScheduled() { | |
CityvisionScheduledLeadScorer cvSLS = new CityvisionScheduledLeadScorer(); | |
String sch = '0 0 23 * * ?'; | |
Test.startTest(); | |
Id jobId = System.schedule('City Vision Lead Scoring', sch, cvSLS); | |
// Get the CronTrigger info prior to the run | |
CronTrigger cronTrigger1 = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE Id = :jobId]; | |
// Assert that the expressions are the same | |
System.assertEquals(sch, cronTrigger1.CronExpression); | |
// Assert that the cron job has not started | |
System.assertEquals(0, cronTrigger1.TimesTriggered); | |
Test.stopTest(); // will execute the asynchronous Apex | |
// Get the CronTrigger info prior to the run | |
CronTrigger cronTrigger_after = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE Id = :jobId]; | |
// Assert that the cron job has run once | |
// TODO: figure out why this is not working | |
System.assertEquals(1, cronTrigger_after.TimesTriggered); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment