用于测试的静态日期时间
我们有一个日期时间服务,可以在需要使用日期时拉取数据库日期。现在,如果我想使用 FitNesse 使用“今天”日期运行测试,创建 (OurService).CurrentDate 静态的最简单方法是什么?
我们有一个控件,可以将天、年或月广告到当前日期..我希望能够对此进行测试。
谢谢!
We have a DateTime Service that pulls the Database date down when we need to use a Date. Now, If I want to run a test using "Todays" Date using FitNesse, What would be the easiest way of creating a way to have (OurService).CurrentDate be static?
We have a control that ads Days,Years, or Months to the current date.. and I would like to be able to test this.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的代码中,添加一个方法以从“某处”提取日期(“某处”是实现细节)。例如,在我的代码中:
替换为:
我现在可以在测试中扩展 X,以使用返回固定日期的内容覆盖
now()
。还要添加一个测试,该测试调用原始实现但忽略结果(好吧,您可以检查结果是否在“现在”的范围内)。此测试只是确保旧的日期拉取代码继续工作。
In your code, add a method to pull the date from "somewhere" ("somewhere" is an implementation detail). For example, in my code:
is replaced with:
I can now extend X in my tests to override
now()
with something that returns a fixed date.Also add a test which calls the original implementation but which ignores the result (well, you can check that the result is within a range of "now"). This test just makes sure that the old date pulling code continues to work.