I created an extension method for the the class Random
which executes an Action
(void delegate) at random times:
public static clas
All answers are correct, and I would like to add a practical view:
When you have a remote non real-time component to test (for example, a search engine), you need to give it time to go to it's new state before you reference it again for assertions. In other words, you want to suspend your test for some time. Since the performance the test itself is irrelevant (please distinguish between the performance of the test and the performance of the component), you sometimes prefer to keep your code (of the test) as simple and straight forward as possible, and you avoid even the minimum complexity of asynchronous code. You could of course start a new test instead of waiting for your component (that's the difference between await Task.Delay()
and Thread.Sleep()
), but the assumption was that you are in a no hurry for that.