Assert.Throws provides the Assert.Throws method for testing exceptions, instead of the ExpectedException attribute. In his original announcement, James Newkirk explains why this is a much better approach, and I can only agree.

However, those of us that for one reason or another use MSTest are currently stuck with the ExpectedException attribute, but I've entered a suggestion on Connect that we get a similar method in MSTest. If you would also like to have Assert.Throws in MSTest, go to the suggestion and vote for it!

Comments (4)

  1. int19h says:

    Interesting. I did not know that MS employees themselves post suggestions via Connect – thought you guys have some inner channels for that.

    Ah well. I have in fact spotted this ticket earlier, and already validated/voted on it.

  2. ploeh says:

    Last time I asked, DevDiv preferred that employees outside their org used Connect just like everyone else.

    I’m sure there are other channels as well, but I didn’t pursue the matter 🙂

  3. Casper says:

    Why not just import the xUnit assembly and use its Assert classes? 🙂 We do that even though we’re using MSTest as the framework. For that matter, the 3.5 extensions are very handy as well.

  4. ploeh says:

    Hi Casper

    That’s a pretty good idea that I hadn’t thought of!

    There may be situations where you can’t really do this for political reasons, but otherwise a good workaround.

    …I’d still like to have it in MSTest, though 🙂

Skip to main content