Writing Test Cases for Scheduled Jobs

public class ScheduledJob {

    @Schedule(minute="*",hour="*", persistent=false)
    public void doWork(){
        System.out.println("Running at: " +LocalDate.now());


I'd be happy to know if we can write Junit test cases for the class.

Appreciate your help.


source to share

1 answer

The fact that your work is scheduled has nothing to do with functionality testing. You are not testing the planning framework, you are testing your own business logic.

Therefore, unit testing becomes simple:

private ScheduledJob job;

public void testLogic() {
    //Do whatever testing you need...


You will know if you have configured your scheduling framework correctly if the (checked) service method you call is called after it has been deployed in whatever container you are using.



All Articles