I want to test code with integration test that uses cron. The code, what runs by integration test, creates entry to cron_schedule table, but cron does not run created cron-job when it is designated. Why?

  • How can I run cron-job that is located in integration database programmatically?
  • Does correctly configured cron also can run cron-job in integration test database?

1 Answer 1


I think you have a case of the x-y problem. You should not need to run a cronjob from the schedule table in the integration test database. Instead write one test, that only tests if the cronjob is configured correctly, and another one that tests execution of the cronjob by calling the execute method directly from the test.

If you want to know more, please show your test code and explain what you are trying to achieve with the test.

  • What do you mean by "calling the execute method directly from the test" the execute method is in xml file? I mean by that, how can I make sure that crontab.xml is correctly composed? Should I test it altogether? Jun 19, 2017 at 19:41
  • @user3748173 I mean, call $cron->execute() (where $cron is your custom cron model) if you want to test what happens when the cron is executed. And if you want, create another test that checks if crontab.xml is working. It seems like you already got this covered in the current test: assert that an entry in cron_schedule exists and be done with it. But you can replace that test with a simpler one: instantiate Magento\Cron\Model\Cron and call getJobs(), then assert that the result contains your job. Jun 20, 2017 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.