nunit-csharp-samples icon indicating copy to clipboard operation
nunit-csharp-samples copied to clipboard

GetExceptionMessage examples?

Open jwvanderbeck opened this issue 6 years ago • 2 comments
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 avatar Feb 13 '19 17:02 jwvanderbeck

@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);

lukzas avatar Oct 28 '19 12:10 lukzas

@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

SeanKilleen avatar Dec 22 '20 15:12 SeanKilleen