java 用于 Quartz 调度器的 Junit
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5321044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Junit for Quartz Scheduler
提问by user650900
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.
我使用 SchedulerFactoryBean 为我的应用程序创建了一个简单的作业。任何人都可以让我知道我如何使用 Junit 测试这个 Job 并确保它在给定的时间间隔内工作正常,并且在此之后应该停止该工作。我创建了一个示例类并测试了它的工作正常,为了停止这个,我必须停止/终止应用程序。
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.
我想尝试使用 Junit 的是:在所需的时间间隔后,作业调用是一个方法,我想测试该方法的返回值以及与此方法相关的其他功能,然后应停止作业。
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.
我将在 Junit 中创建一个 First 实例,然后睡眠一段时间。在睡眠之间,作业将调用重新加载,这将填充 myData。现在我需要使用 Junit 测试 myData 中的值。
I created this Job using the below link: http://www.mkyong.com/spring/spring-...duler-example/
我使用以下链接创建了这个工作:http: //www.mkyong.com/spring/spring-...duler-example/
Thanks in Advance.
Khan
提前致谢。
汗
回答by Alex Yang
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.
您可以添加一个代码部分:while (true) {}
避免 JUnit 线程结束。但这不是推荐的方法。因为如果你使用 maven 或 hudson 进程会被这种方法阻塞,并且构建将失败。