I created a custom attribute for unit testing based ExpectedExceptionBaseAttribute:
public class ExpectedEngineExceptionAttribute : ExpectedExceptionBaseAttribute
I override the Verify method as follow:
protected override void Verify(Exception exception)
{
RethrowIfAssertException(exception);
throw new Exception("Hola!!");
}
Here's the TestMethod (It calls a method that throws a ):
[TestMethod]
[ExpectedEngineExceptionAttribute()]
public void MyTest()
{
SomeCode();
}
The output in the unit testing window just shows:
Exception has been thrown by the target of an invocation.
I would except to see the message Hola!!
When I run the following Test Method:
[TestMethod]
[ExpectedException(typeof(EngineException))]
public void MyTest2()
{
SomeCode();
}
The output is :
Test method NotificationInputAttributeInvalidTypeTest threw exception System.Exception, but exception EngineException was expected. Exception message: System.Exception: SS
What am I missing to have my "Hola" exception message to show in the output window?
I decompiled the ExpectedExceptionAttribute and did what it does in my custom attribute but it's not working...
UPDATE: Adding a breakpoint confirms the Exception("Hola!!") is thrown:


Hola!!