The next release of Gallio (v3.0.7) contains an impressive number of new features (VS2010 Support, Control Panel, Test With Debugger in Icarus, and many more). But we have also worked hard to extend MbUnit v3 with some new interesting capabilities. I am going to present them briefly to you in the following articles. Please remember that you are not forced to wait for the official release of Gallio v3.0.7 to play with them. You can download the latest daily build here. It is possible that you experiment some minor issues with the daily builds (let us know on the newsgroups here and there), but they are very stable already.I will start today with the new special assertion
Retry.Until
. It is special because it is not of the usual form Assert.Something
. Retry.Until
lets you evaluate a specific condition several times until it becomes true, or until some timeout mechanism triggers an assertion failure.The assertion comes with a nice fluent syntax which allows some flexible configuration. It works a little bit like the famous Rhino.Mocks expectations. You can specify the number of times the condition must be evaluated (Times
), a polling time between each evaluation (WithPolling
), a global timeout duration for the entire operation (WithTimeout
), or some custom action to execute between each cycle (DoBetween
). Of course, you can finally specify the condition to evaluate (Until
). So far, 3 kinds of conditions are accepted:- A
WaitHandle
instance which is expected to be signaled. - A
Thread
instance which is expected to be terminated. - A versatile predicate
Func<bool>
which is expected to return true.
[TestFixture]
public class MyTestFixture
{
[Test]
public void MyTestMethod()
{
var foo = new Foo();
foo.RunSomeAsyncOperation();
Retry.Times(5)
.WithPolling(TimeSpan.FromSeconds(1))
.Until(() => Foo.HasTerminated());
}
}