Sunday, 28 October 2012
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
© 2011-2018 Nikos Baxevanis. All written content on this site is provided under a Creative Commons ShareAlike license. All code is provided under a MIT license unless otherwise stated.