对调度程序进行单元测试有哪些策略? [英] What are some strategies to unit test a scheduler?
问题描述
这篇文章的开头是单元测试多线程代码中有哪些常见模式?,但我发现了一些 other 讨论在SO上通常同意It is Hard(TM)和It Depends(TM)。所以我认为减少问题的范围会更有用。
This post started out as "What are some common patterns in unit testing multi-threaded code ?", but I found some other discussions on SO that generally agreed that "It is Hard (TM)" and "It Depends (TM)". So I thought that reducing the scope of the question would be more useful.
背景 :我们正在实施简单的调度程序,为您提供在启动和停止作业时注册回调的方法,当然还可以配置调度的频率。目前,我们正在围绕java.util.Timer制作一个轻量级包装。
Background : We are implementing a simple scheduler that gives you a way to register callbacks when starting and stopping jobs and of course configure the frequency of scheduling. Currently, we're making a lightweight wrapper around java.util.Timer.
方面 :
Aspects:
-
我还没有找到一种方法来依赖公共接口来测试这个调度程序(类似于
addJob( jobSchedule,jobArgs,jobListener)
,removeJob(jobId)
)。
如何根据指定的时间表计算作业被调用的事实?
How do I time the fact that the the job was called according to the schedule specified ?
推荐答案
您可以使用记录器对象记录每个单元测试中的顺序,时间和其他有用的东西您的调度程序。测试很简单:
you could use a recorder object that record the order, timings and other useful stuff in each unit test of your scheduler. The test is simple:
- 创建记录器对象
- configure时间表
- 执行单元测试
- 检查记录器对象是否与日程表兼容
- create a recorder object
- configure the schedule
- execute a unit test
- check that recorder object is "compatible" with the schedule
这篇关于对调度程序进行单元测试有哪些策略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!