2

Is it possible to use Assert.DoesNotThrow with a particular exception type?

For example how do I verify that a method call is not throwing NullReferenceExceptions specifically but it may throw NotSupportedException which I don't care about. ?

3
  • 1
    I think that Assert.DoesNotThrow comes from NUnit or XUnit, not from FakeItEasy. Commented Feb 15, 2015 at 9:52
  • 'Assert.DoesNotThrow' it self is not there in the new release of XUnit github.com/xunit/xunit/issues/188. I'm still trying to understand the justification behind this decision. Commented Feb 15, 2015 at 10:39
  • 4
    Brad: "Every single line of code is an implicit "does not throw", because if it throws, then the test fails." Commented Feb 16, 2015 at 16:12

1 Answer 1

8

There's a pattern null checking in xUnit.

var ex = Record.Exception(...);
Assert.Null(ex);

It's bit late; however, hope it helps you :).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.