Testing async methods with MbUnit

XUnit 1.9 recently shipped, featuring support for async tests:

[Test]
public async Task MyAsyncUnitTest()
{
    // ... setup code here ...

    var result = await CallMyAsyncApi(...);

    // ... assertions here ...
}

Here’s how that looks using MbUnit:

public class AsyncTestAttribute : TestAttribute
{
	/// <inheritdoc />
	protected override void Execute(PatternTestInstanceState state)
	{
		var result = state.InvokeTestMethod();

		var task = result as Task;
		if (task != null)
			task.Wait();
	}
}

Sweet! This’ll be in the next MbUnit/Gallio release (but only if you also reference MbUnit40.dll).