Writing Test Cases for Scheduled Jobs

@Singleton
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.

+3


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:



@Inject
private ScheduledJob job;

@Test
public void testLogic() {
    //Do whatever testing you need...
    job.doWork();
}

      

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.

+2


source







All Articles