问题
I have created a simple Job using SchedulerFactoryBean for my application. Can anyone please let me know how do I test this Job using Junit and make sure that is working fine for the interval given and the job should be stopped after that. I have created a sample class and have tested its working fine, for stopping this I have to stop/kill the application.
What I want to try using Junit is: The Job call's a method after a required interval, I want to test the return value of the method and other functionalities associated with this method and then the job should be stopped.
public class First {
private HashMap myData = null;
public void reload(){
myData = calling some method;
}
}
I will create an instance of First in Junit then sleep for some interval. In between the sleep the reload will be called by the Job and that will fill the myData. Now I need to test the value in myData with Junit.
I created this Job using the below link: http://www.mkyong.com/spring/spring-...duler-example/
Thanks in Advance.
Khan
回答1:
You can add a code section :while (true) {}
to avoid JUnit thread ends. But it's not an recommend method. Because if you use maven or hudson the process will blocked by this method, and the build will failed.
来源:https://stackoverflow.com/questions/5321044/junit-for-quartz-scheduler