Click here to Skip to main content
15,892,005 members
Articles / Programming Languages / C#

Making Time-dependent Features Testable

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
17 Oct 2020MIT6 min read 4.4K   44   5  
Description of the technique that makes the time-dependent code unit-testable
As professional developers, we are all striving to provide 100% automated test coverage for all code we write. However, one particular class of features is quite difficult to test - those that depend on current time, in one way or another. For example, an expiring token - how we test that it actually expires in 20 minutes? In this article, I share a simple technique that helps with this challenge, that I have been personally using for quite some time. As an extra bonus, I will also share the 'simplest' stopwatch utility methods.

Views

Daily Counts

Downloads

Weekly Counts

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer (Senior) Microsoft
United States United States
25 years of professional experience. .NET/c#, databases, security.
Currently Senior Security Engineer, Cloud Security, Microsoft

Comments and Discussions