Time is an integral part of our lives — the same for the applications we develop. From the software engineering perspective, time is just another dependency which we introduce to our systems. And that’s OK. The situation might start to be problematic when some parts of the system are more dependent on time. How to test this component? How to mock the time?
In this article, I’m going to show you our approach to develop and test components which depend on time. We’ll get rid of time-dependency by creating a proper abstraction and applying the dependency inversion principle. Ultimately, we’ll create a mechanism to mock time in tests. Ready?