« xUnit.net 1.0 Released Today | Main | Lessons Learned in Programmer Testing »

June 25, 2008


TrackBack URL for this entry:

Listed below are links to weblogs that reference Replacing ExpectedException in NUnit:

» ExpectedException considered harmful! from James Newkirk's Blog
I have written a blog post detailing the issues that I have with ExpectedException. Also, I am not just [Read More]


Feed You can follow this conversation by subscribing to the comment feed for this post.

Keith J. Farmer

My biggest complaint about ExpectedException was that you were never able to validate that, amoung all exceptions of a particular type, that you were able to verify the correct message in a localizable manner.

So we, too, created an expected exception method, that took the expected exception method as well. We also went a little further, and took a params Action[] so we would assert for each test in a sequence within a particular method.


You could put details in the expected exception to isolate a particular exception.

[ExpectedException( typeof( ArgumentException ), ExpectedMessage="Deposit amount cannot be zero" )]


[ExpectedException( "System.ArgumentException", ExpectedMessage="Deposit amount cannot be zero" )]

Hence this code would fail because it had the wrong message. You would then change the test to fix the problem with the setup of checking account.

The comments to this entry are closed.