Checking expected exception message when using MS Test

20 באוגוסט 2009

תגיות: , , , ,
3 תגובות

My blog has moved. You can view this post at the following address: http://blog.drorhelper.com/2009/08/checking-expected-exception-message.html

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *

3 תגובות

  1. Yoav Michaeli20 באוגוסט 2009 ב 14:12

    you can check the error message with the attribute [ExpectedException(typeof(CriticalException), "An error occured")]
    see http://stackoverflow.com/questions/113395/how-can-i-test-for-an-expected-exception-with-a-specific-exception-message-from-a

    הגב
  2. dhelper20 באוגוסט 2009 ב 14:34

    Actually you can't!
    MSTest uses the string as a description and not as verification (like we're used from NUnit).

    See this post (as well as MS documentation): http://imistaken.blogspot.com/2008/09/mstest-expectedexception-and-exception.html

    הגב
  3. lior20 באוגוסט 2009 ב 17:30

    BTW NUnit also added the Assert.Throw syntax in the 2.5 version.
    Im guessing that like alwyas only MS is left behind (but im sure its a matter of time since we will see that as well).

    The only thing that I don't like about the assert.throw is that it forces you to mix the "act" part of the test with the "assert".

    הגב