Testing async methods with MbUnit

XUnit 1.9 recently shipped, featuring support for async tests:

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)

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s