To check exception messages, I cannot use Assert.That(), my prefered way, because it returns nothing. The only way I can use is Assert.Throws(). Assert.Throws() returns an instance of the exception, and using it, I can check the message.
ArgumentException ex = Assert.Throws<ArgumentException>(delegate { clz.Divide(3, 0); });
Assert.AreEqual("Hey man, you need to learn elementary school again!", ex.Message);
Happy testing! :-)
No comments:
Post a Comment