locked
Running a Unit Test in debug mode with an ExpectedException causes debugger to break RRS feed

  • Question

  • When the following unit tests are run in non-debug mode they work as expected. But when the unit tests are run in debug mode the debugger breaks on the "Throw New ..." line with an "ApplicationException was unhandled by user code" (or "NotImplementedException was unhandled by user code") error.

    Any ideas? This worked in VS2008.

    Public Class Class1
    
     Public Sub ThrowNotImplementedException()
      Throw New NotImplementedException
     End Sub
    
     Public Sub ThrowApplicationException()
      Throw New ApplicationException
     End Sub
    
    End Class
    
    <TestClass()>
    Public Class Class1Test
    
     <TestMethod()>
     <ExpectedException(GetType(NotImplementedException))>
     Public Sub ThrowNotImplementedExceptionTest()
      Dim target As Class1 = New Class1()
      target.ThrowNotImplementedException()
     End Sub
    
     <TestMethod()>
     <ExpectedException(GetType(ApplicationException))>
     Public Sub ThrowApplicationExceptionTest()
      Dim target As Class1 = New Class1()
      target.ThrowApplicationException()
     End Sub
    
    End Class
    
    Tuesday, April 27, 2010 2:07 PM

Answers

  • The default behavior for unhandled exceptions when running in debug mode is to break when the exception is thrown - and this is exactly what you are seeing.  You can either select 'continue' to continue execution, and show the test as running successfully, or you can unselect the checkbox for breaking on unhandled exceptions (from the Debug | Exceptions... menu).

    I believe that by default this was unchecked in VS2008, but by default it is checked in VS2010 (I'm not at a computer with VS2008 installed right now to verify this...).

    Hope this helps!

    Wednesday, May 5, 2010 9:21 AM