Skip to content

Dynamically assert exception type with xUnit Theory #2049

Answered by jnyrup
sgabler asked this question in Q&A
Discussion options

You must be logged in to vote

You're so close!

In our test suite we use have this test using a generic test and non-generic memberdata.

[Theory]
[MemberData(nameof(AggregateExceptionTestData))]
public void When_the_expected_exception_is_wrapped_it_should_succeed<T>(Action action, T _)
where T : Exception
{
// Act/Assert
action.Should().Throw<T>();
}

I just checked and you should be able to use

[Theory]
[MemberData(nameof(InvalidProcessAccessTokenInput))]
public async Task ProcessAccessTokenInput_should_throw_exception_for_invalid_input<T>(TokenController.Acc…

Replies: 1 comment 1 reply

Comment options

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

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