Welcome to MSDN Blogs Sign in | Join | Help

Assert.Throws

xUnit.net 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!

Published Wednesday, November 12, 2008 10:17 AM by ploeh
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Assert.Throws

Wednesday, November 12, 2008 12:05 PM by int19h

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.

# re: Assert.Throws

Wednesday, November 12, 2008 1:03 PM by ploeh

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 :)

# re: Assert.Throws

Monday, November 17, 2008 1:02 PM by casper

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.

# re: Assert.Throws

Monday, November 17, 2008 1:40 PM by ploeh

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 :)

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker