Hello, I’m wondering if there is any way to unit test on countdown timer? If yes, can I get an example.
1 Like
Yes, but I dont know what your code looks like.
I cobbled together a test and a Timer class here. Its all in one file so you’d have to move the ITime
interface and Timer
class to your usual script locations. The idea here is to mock out the hard to test part which is time. For that I created an ITime interface and made a mock implementation for easy testing. Implement your own ITime that simply returns Time.deltaTime in the delta
getter. Resetting the level is done by hooking up with the expired
event. It fires once per call to ResetDuration
, on the timers expiry.