I am using C# 3.0 and NUnit. I’m wondering if there is a standard way to perform unit tests on code that executes after some amount of time. For example, I have a simple static class that I can register methods with, and have them be called n milliseconds later. I need to assure that code in the delegate methods is being called.
For example, the following test will always pass, because there are no assertions made until after the method has exited.
[Test] public void SampleTest() { IntervalManager.SetTimeout(delegate{ Assert.Equals(now.Millisecond + 100, DateTime.Now.Millisecond); }, 100); }
Is it even possible to unit test code that doesn’t execute immediately?
Cheers,
Paul
How about this? It causes the test to block for some expected maximum time for the callback to fire and complete before bailing, reporting an error.