— New online course!  Getting Started with Azure DevOps — Special launch price 50% off —

Silverlight Unit Tests: How to Stop Breaking on Assert Exceptions

by

There’s something a little peculiar about how unit tests work in Silverlight when the debugger is attached – when an Assert fails in one of your unit tests, the Visual Studio debugger breaks the execution and brings up the debugger dialog.

image

If you want to run a whole bunch of unit tests to see which ones are failing or you only care about the exceptions that your code throws, this feature can really cramp your style.  Thankfully, it’s pretty easy to edit the debugger settings to make these Assert exceptions go away.

Step #1: Go to the Debug menu in Visual Studio 2010, choose Exceptions…

image

Step #2: On the Exceptions dialog, click Add… 

image

Step #3: Register the exception types you want to tweek

image

From the Type menu, choose Common Language Runtime Exceptions.
In the Name textbox, type Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException.
Click OK.

Step #4: Repeat step #2 and #3 for Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException

Step #5: Uncheck Thrown and User-unhandled for the exceptions you just added.

image

Step #6: On the Exceptions dialog, click OK

image

Step #7: Enjoy your new streamlined exceptions.

image

-Ben


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: