Reputation: 4449
I'm writing a unit test for a timer I created and I'm running into a problem I encounter often with other projects. I would like to create a unit test that starts my timer, waits a few moments, and then checks the value of my timer after the timer has been run. I could then test all the functionality I have in my timer.
Is there a way to do this? I don't see anything in the documentation. If this is not a good practice, please advise what I should do instead.
Upvotes: 1
Views: 932
Reputation: 1135
If you're unit-testing anything involving time you probably want to virtualize your notion of time so you can change it manually. Depending on what you're using for your timer this may be easier or harder to do (or built in), but once you've done it you can then write your unit tests using something like "setVirtualTime(time)".
Some advantages of this approach:
Upvotes: 5