locked
Unit Tests no longer stop on errors during debugging RRS feed

  • Question

  • After a few weeks away, I returned to one of my C# projects to find that unit test runs no longer stop on exceptions. Under normal circumstances, when execution hits an exception, it displays a callout/popup summarizing the exception, giving troubleshooting tips, allowing detail drilldown, etc (I can't post images yet so hopefully you know what I'm talking about).

    The following dummy console application does produce this popup:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                throw new ArgumentNullException("Test", "TestMessage");
            }
        }
    }


    An equivalent dummy unit test just runs all the way through and shows the error in the summary pane instead of stopping on the line that throws the exception:

    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    
    namespace TestTest
    {
        [TestClass]
        public class UnitTest1
        {
            [TestMethod]
            public void TestMethod1()
            {
                throw new ArgumentNullException("Test", "TestMessage");
            }
        }
    }

    Here is what shows up in the output immediately after the exception is thrown.  The second line suggest something wonky is happening when it tries to process the exception, but that could be a red herring:

    A first chance exception of type 'System.ArgumentNullException' occurred in TestTest.dll
    A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
    A first chance exception of type 'Microsoft.VisualStudio.TestPlatform.MSTestFramework.TestFailedException' occurred in Microsoft.VisualStudio.TestPlatform.Extensions.VSTestIntegration.dll
    A first chance exception of type 'Microsoft.VisualStudio.TestPlatform.MSTestFramework.TestFailedException' occurred in Microsoft.VisualStudio.TestPlatform.Extensions.VSTestIntegration.dll
    

    Why is this happening and how do I fix it?  I am running the unit test by right-clicking the test and choosing "Debug Selected Tests"

    Note: this a completely new dummy project that I set up to test this specific issue.  I haven't changed any settings from defaults.

    Software summary:

    Visual Studio Professional 2013

    Version 12.0.31101.00 Update 4

    .NET framework 4.5.50938

    Wednesday, July 8, 2015 5:11 PM

Answers

  • Hi S. Triplett,

    >>An equivalent dummy unit test just runs all the way through and shows the error in the summary pane instead of stopping on the line that throws the exception

    Based on your issue, I suggest you could try to click the DEBUG->Exceptions->enable these User-unhandled options like this following screen shot.

    And then run the unit test by right-clicking the test and choosing "Debug Selected Tests" check this issue again.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Tina-Shi Wednesday, July 15, 2015 11:44 AM
    Thursday, July 9, 2015 7:33 AM