Use NUnit Assert.Throws method or ExpectedException attribute?

后端 未结 5 1263
温柔的废话
温柔的废话 2020-12-04 13:57

I have discovered that these seem to be the two main ways of testing for exceptions:

Assert.Throws(()=>MethodThatThrows());

[ExpectedExc         


        
5条回答
  •  感动是毒
    2020-12-04 14:18

    The first allows you to test for more than one exception, with multiple calls:

    Assert.Throws(()=>MethodThatThrows());
    Assert.Throws(()=>Method2ThatThrows());
    

    The second only allows you to test for one exception per test function.

提交回复
热议问题