Visual Studio “Debug Unit Test” fails to hit breakpoints

前端 未结 11 2014
天涯浪人
天涯浪人 2020-12-17 07:28

When using Visual Studio 2008 and debugging my unit tests... sometimes the debugger works fine. However very often after modifying some code then clicking \"Debug Unit Test\

相关标签:
11条回答
  • 2020-12-17 08:30

    If you are using a setup method with [TestInitialize] \ [ClassInitialize] attribute (mstest \ nunit)? try to check if that setup code is being executed successfully.

    For example:

    [TestInitialize]
    public void Setup()
    {
        throw new Exception();
    }
    
    [TestMethod]
    public void SomeFooTest()
    {
        //The breakpoint will "Fail" to hit here.
    }    
    

    In visual studio you can easily see this behavior with Test Explorer or by the CodeLens (only in professional):

    0 讨论(0)
  • 2020-12-17 08:31

    Now we have this problem with Visual Studio 2017 15.5 and Resharper 2017.2. Problem caused by Resharper and solved in latest versions 2017.3+

    link

    0 讨论(0)
  • 2020-12-17 08:32

    What happened to be the solution for me: make sure all your nuget package versions match. My Unit Test project was using a version of Newtonsoft.Json that was newer than the Newtonsoft.Json reference on the project I was testing. Once I updated all nuget packages to the latest version I was able to hit the breakpoint

    0 讨论(0)
  • 2020-12-17 08:32

    The breakpoint is not hit when starting debugging from the "Unit Test Sessions" window (Resharper - Windows - Unit Test Sessions) which comes from ReSharper.

    But when starting the test from the "Test Explorer" window (Test - Windows - Test Explorer) of VS it hits the breakpoint.

    VS Enterprise 2017 V15.5.6, ReSharper 2017.2.2

    The latest ReSharper 2017.3.1 is not an option because it has other bugs

    0 讨论(0)
  • 2020-12-17 08:35

    I had the same problem, although I don't have permanent solution, this is a quick one time fix: Debug the unit test (Ctrl-T, Ctrl-D), then go to "Immediate Window", enter anything (e.g. 'a' or null) and press enter. After this the break point will be hit.

    0 讨论(0)
提交回复
热议问题