In unit testing, there are times were the SUT has to be exercised asynchronously.
How can we wait for the exercise to complete execution?
// Fixture setup var sut = new ObjectLocalStorage(); sut.Set(@object, expected); object result = null; // Exercise system new Task(() => result = sut.Get(@object)).Start(); SpinWait.SpinUntil(() => result != null); // Verify outcome Assert.Equal(expected, result); // Teardown
Taskhas been created it is immediately scheduled for execution by calling the
There is also a SpinUntil overload accepting a TimeSpan timeout.━━━
This post has been filed under xunit.net
© 2012-10-28 Nikos Baxevanis <email@example.com>