Skip to content

XUnit ThrowsAsync<> doesn't seem to be checking the exception type. Is this a bug? #2601

Answered by vjmanda
vjmanda asked this question in Question
Discussion options

You must be logged in to vote

Apparently its due to not awaiting ThrowsAsync itself.

public class AssertThrowsTests
{
	[Fact]
	public async Task Tests()
	{
		// Using a method as a delegate
		await Assert.ThrowsAsync<NotImplementedException>(async () => await MethodThatThrows());
	}

	async Task MethodThatThrows()
	{
		await Task.Delay(100);
		throw new NotImplementedException();
	}
}

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@bartelink
Comment options

Answer selected by bradwilson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants