Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetExceptionMessage examples? #17

Open
jwvanderbeck opened this issue Feb 13, 2019 · 2 comments
Open

GetExceptionMessage examples? #17

jwvanderbeck opened this issue Feb 13, 2019 · 2 comments

Comments

@jwvanderbeck
Copy link

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.

@lukzas
Copy link
Contributor

lukzas commented Oct 28, 2019

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

@SeanKilleen
Copy link
Member

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants