Skip to content

Instantly share code, notes, and snippets.

Created January 24, 2013 00:37
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save haacked/4616366 to your computer and use it in GitHub Desktop.
An async version of xUnit's Async.Throws. Use it like so: await ThrowsAsync<AuthenticationException>(async () => await obj.GetStuffAsync());
public async static Task<T> ThrowsAsync<T>(Func<Task> testCode) where T : Exception
await testCode();
Assert.Throws<T>(() => { }); // Use xUnit's default behavior.
catch (T exception)
return exception;
return null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment