I am completely new to C # and NUnit.
Boost.Test has a macro family BOOST_*_THROW. There is a method in the Python test module TestCase.assertRaises.
As I understand it, in C # with NUnit (2.4.8), the only method for checking exceptions is to use ExpectedExceptionAttribute.
Why do I prefer ExpectedExceptionAttributeover - let say - Boost.Test approach? What reasoning can be behind this design decision? Why is this better with C # and NUnit?
Finally, if I decide to use it ExpectedExceptionAttribute, how can I do some additional tests after the exception has been raised and caught? Let's say that I want to check the requirement that the object must be valid after any setter has raised System.IndexOutOfRangeException. How would you fix the following code to compile and work as expected?
[Test]
public void TestSetterException()
{
Sth.SomeClass obj = new SomeClass();
Assert.Raises( "System.IndexOutOfRangeException",
obj.SetValueAt( -1, "foo" ) );
Assert.IsTrue( obj.IsValid() );
}
Edit: Thanks for your answers. Today I found a blog entry mentioning all three of the methods you described (and another minor variation). I am ashamed that I could not find him before: - (.
source
share