nunit-csharp-samples
nunit-csharp-samples copied to clipboard
GetExceptionMessage examples?
trafficstars
Hi, I could not find any examples of using the callback to get the exception message. It would be very helpful to include a few examples of this.
@jwvanderbeck if you want to test exception message you could try something like
Assert.Throws(Is.TypeOf<InvalidOperationException>()
.And.Message.EqualTo("I am the test exception"),
() => fixture.TestThatThrowsException());
or
var ex = Assert.Throws<InvalidOperationException>(() => fixture.TestThatThrowsException());
Assert.AreEqual("I am the test exception", ex.Message);
@jwvanderbeck I know this issue is a bit old, but please let me know if the example on our Assert.Throws docs is clear enough; if not, feel free to file an issue / PR over there too: https://docs.nunit.org/articles/nunit/writing-tests/assertions/classic-assertions/Assert.Throws.html