开发者

In MS C# Unit Testing, how to Assert that an ArgumentException occured?

开发者 https://www.devze.com 2023-01-07 04:48 出处:网络
If we do a throw new ArgumentExcep开发者_Python百科tion(\"Cannot do that\"); How do you Assert that this ArgumentException happened with Microsoft\'s Testing Framework?You could decorate your unit

If we do a

throw new ArgumentExcep开发者_Python百科tion("Cannot do that");

How do you Assert that this ArgumentException happened with Microsoft's Testing Framework?


You could decorate your unit test with the [ExpectedException] attribute:

[ExpectedException(typeof(ArgumentException))]
[TestMethod]
public void Foo()
{
    throw new ArgumentException("foo");
}

Don't ask though about asserting the exception message :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消