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.

Silverlight Unit Tests: How to Stop Breaking on Assert Exceptions

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…

Silverlight Unit Tests: How to Stop Breaking on Assert Exceptions

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

Silverlight Unit Tests: How to Stop Breaking on Assert Exceptions

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

Silverlight Unit Tests: How to Stop Breaking on Assert Exceptions

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.

Silverlight Unit Tests: How to Stop Breaking on Assert Exceptions

Step #6: On the Exceptions dialog, click OK

Silverlight Unit Tests: How to Stop Breaking on Assert Exceptions

Step #7: Enjoy your new streamlined exceptions.

Silverlight Unit Tests: How to Stop Breaking on Assert Exceptions

相关文章: