MS Test : How do I enforce exception message with ExpectedException attribute

Posted by CRice on Stack Overflow See other posts from Stack Overflow or by CRice
Published on 2011-01-17T04:55:16Z Indexed on 2011/01/17 8:53 UTC
Read the original article Hit count: 266

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about nunit

Related posts about mstest