MS Test : How do I enforce exception message with ExpectedException attribute
- by CRice
I thought these two tests should behave identically, in fact I have written the test in my project using MS Test only to find out now that it does not respect the expected message in the same way that nunit does.
nunit (fails):
[Test, ExpectedException(typeof(System.FormatException), ExpectedMessage = "blah")]
public void Validate()
{
int.Parse("dfd");
}
ms test (passes):
[TestMethod, ExpectedException(typeof(System.FormatException), "blah")]
public void Validate()
{
int.Parse("dfd");
}
No matter what message I give the ms test, it will pass.
Is there any way to get the ms test to fail if the message is not right? Can I even create my own exception attribute? I would rather not have to write a try catch block for every test where this occurs.