In the past I have tested for expected exceptions like this:
[TestMethod]
public void TestThrowsException() {
try {
Foo();
Assert.Fail();
} catch (MyException ex){//good
}
}
However I notice that there is a (cleaner?) way to test this using the ExpectedException attribute. Why does this test method pass when the exception is not thrown? Surely this defeats the purpose of the attribute.
[TestMethod]
[ExpectedException(typeof(MyException))]
public void TestThrowsException() {
}
[Edit] I am running this test using Silverlight 2