ExpectedException Assert

前端 未结 5 1216
死守一世寂寞
死守一世寂寞 2021-02-08 05:25

I need to write a unit test for the next function and I saw I can use [ExpectedException]

this is the function to be tested.

public static T FailIfEnumIs         


        
5条回答
  •  情深已故
    2021-02-08 05:54

    You don't need an assertion if you're using ExpectedException attribute, in fact your code shouldn't be able to arrive at the assertion.

    look: http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.expectedexceptionattribute.aspx

    If you want to be sure the exception is thrown you should put an Assert.Fail() after the operation that should throw the exception, in this case if the exception is not thrown, the test will fail.

提交回复
热议问题