[Test]
[ExpectedException(typeof(ArgumentException))]
public void DivideANumberByZeroShouldThrowException()
{
// do nothing
}
I can use NUnit test runner, but I prefer to use ReSharper built-in test runner, which provides visualization to see the result. Should I ignore NUnit 2.5?
Update: After a while, I have the answer is "No". But to use ReSharper to run tests with expected exceptions, I need to change the way how to write test code. There are 2 ways to make the test runs well:
Assert.That(delegate { clz.Divide(3, 0); }, Throws.InstanceOf<ArgumentException>());
and
Assert.Throws<ArgumentException>(delegate { clz.Divide(3, 0); });
I prefer the first way.
Reference:
Update: Good to know that now ReSharper's NUnit runner can run tests with ExpectedException attribute, v4.5.1 (http://www.jetbrains.net/devnet/thread/281286?tstart=0)
No comments:
Post a Comment