You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 20, 2018. It is now read-only.
hatchan edited this page Mar 28, 2011
·
5 revisions
Creating unit tests where time is involved can be tricky, if not impossible. The reason for this is that the time is always different when you run your unit test. You should see getting the current time as accessing a external system and as with any other external system (web service, database, etc), you should not depend on it directly. You should depend on a interface, so you can use different implementations for unit testing, development and production. To help I've created the TimeServices library.
TimeServices
TimeServices provides a way to access the current time but it makes it possible to switch implementation. It has been created with Dependency Injection in mind, so you can use it with you favorite container or use poor mans dependency injection. The library provides a basic interface, IClock, which provides a few ways to get the current time. It also provides a few basic implementations:
SystemClock: Get the time from the system (production)
FixedClock: Get the time from the values provided (unit tests)