Junit for Quartz Scheduler [英] Junit for Quartz Scheduler

查看:222
本文介绍了Junit for Quartz Scheduler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的应用程序使用SchedulerFactoryBean创建了一个简单的Job.任何人都可以让我知道如何使用Junit测试此作业,并确保该作业在给定的时间间隔内可以正常工作,并且此后应停止该作业.我已经创建了一个示例类并测试了它的正常工作,要停止该类,我必须停止/终止该应用程序.

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.

我想尝试使用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.

 public class First {
   private HashMap myData = null;

   public void reload(){
     myData = calling some method;
   }
}

我将在Junit中创建First的一个实例,然后休眠一段时间.在两次睡眠之间,Job将调用重新加载,并且将填充myData.现在,我需要使用Junit测试myData中的值.

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.

我使用以下链接创建了这份工作: http://www .mkyong.com/spring/spring -... duler-example/

I created this Job using the below link: http://www.mkyong.com/spring/spring-...duler-example/

预先感谢.

Thanks in Advance.
Khan

推荐答案

您可以添加代码段:while (true) {}以避免JUnit线程结束.但这不是推荐的方法.因为如果您使用maven或hudson,则此方法将阻止该过程,并且构建将失败.

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.

这篇关于Junit for Quartz Scheduler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆