Writing tests for CRON job

#1

How I could write a test that checks my cron job will run at an expected time?
The CRON job is something like this 0 0 0 ? * * * which is basically will run the job at 00:00:00am every day!
I tried with something like:

var cron = CronJob.get('my-cron-job');
var def = cron.scheduleDef;

but with scheduleDef I get back only the expression, how I could get the next execution time to check it with expected datetime?

0 Likes

#2
0 Likes

#3

Basically what I am trying to do is having a test file of this form:

var filename = 'test-cron-job-awesomness';
describe(filename, function() {
  var ctx;
  it("setup context", function () {
    ctx = TestApi.createContext(filename);
  });
  
  it("should have some awesomeness", function() { 
    // here goes the awesomeness test
  });
});

My questions are:

  1. how I can get the next schedule time for my CRON job so that I can check it with the expected datetime?
  2. are there other things that I should be testing? (I already have a test for the logic)
0 Likes