How do I use Assert.Throws to assert the type of the exception?

后端 未结 7 1611
你的背包
你的背包 2020-12-02 04:51

How do I use Assert.Throws to assert the type of the exception and the actual message wording?

Something like this:

Assert.Throws

        
7条回答
  •  我在风中等你
    2020-12-02 05:24

    You can now use the ExpectedException attributes, e.g.

    [Test]
    [ExpectedException(typeof(InvalidOperationException), 
     ExpectedMessage="You can't do that!"]
    public void MethodA_WithNull_ThrowsInvalidOperationException()
    {
        MethodA(null);
    }
    

提交回复
热议问题