0

I am running a @Scheduled method at the end of every month. How would I go about testing that? I've heard of awaitility for simple async call backs but this would be a rather long await.

I've heard of businessTime, where you could simply set the time and to a second before the @Scheduled time, but no clue as to how to set it up. Other than that, I am somewhat baffled.

This is the the annotation I have. Can you work around this with @Profile?

@Scheduled(cron = "0 0 0 30 * ?")
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Norls
  • 19
  • 1
  • 8
  • 2
    If you want to make sure it executes every month, then you are testing Spring, not your code. If you need to test your `cron`, there is a similar question: https://stackoverflow.com/a/52167381/9922752 – DelfikPro Jan 26 '21 at 11:31
  • Do you have to test that the Spring Boot functionality works? – wjans Jan 26 '21 at 11:31
  • @wjans yes, that would be the end goal, just now realizing the flaw in my thinking, being able to simply run the code without having to wait for the cron job to kick in... Thanks! – Norls Jan 26 '21 at 12:03

1 Answers1

0

Since I simply wanted to test the contents of the method with the @sheduled annotation, I can just do that like any other test.

If you want to test the actual cron job, be sure to checkout the answer over at: https://stackoverflow.com/a/52167381/9922752 as recommended by @DelfikPro.

Norls
  • 19
  • 1
  • 8