<p>I am currently writing a simple, timer based mini app in C# that performs an action n times every k seconds.<br>
I am trying to adopt a test driven development style, so my goal is to unit test all parts of the app.</p>

<p>So, my question is: Is there a good way to unit test a timer based class?</p>

<p>The problem, as I see it, is that there is a big risk that the tests will take uncomfortably long to execute, since they must wait so and so long for the desired actions to happen.<br>
Especially if one wants realistic data (seconds), instead of using the minimal time resolution allowed by the framework (1 ms?).<br>
I am using a mock object for the action, to register the number of times the action was called, and so that the action takes practically no time.</p>

I think what I would do in this case is test the code that actually executes when the timer ticks, rather than the entire sequence. What you really need to decide is whether it is worthwhile for you to test the actual behaviour of the application (for example, if what happens after every tick changes drastically from one tick to another), or whether it is sufficient (that is to say, the action is the same every time) to just test your logic.
Since the timer's behaviour is guaranteed never to change, it's either going to work properly (ie, you've configured it right) or not; it seems to be to be wasted effort to include that in your test if you don't actually need to.