C# testing — why does ExpectedException tagged method pass when exception not thrown?
问题 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