Visual Studio “Debug Unit Test” fails to hit breakpoints

前端 未结 11 2013
天涯浪人
天涯浪人 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:11

    Make sure you are debugging the correct test!

    I have some tests with very similar names except for the last word in the test name. I had the break point set in the first test and was using Visual Studios "Test Explorer" window to "Debug Selected Tests" on the second test, which didn't have a breakpoint set.

    Test names

    PublishAsync_Valid_Acked
    PublishAsync_Valid_Nacked
    
    0 讨论(0)
  • 2020-12-17 08:14

    I just had a problem hitting breakpoints in VS2015.

    I am always using the solution configuration called Debug but for some reason my solution was set to build the Release version.

    Switching from Release to Debug in the dropdown at the top of Visual Studio fixed my problem.

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

    Another workaround: Force the debugger to be launched from within your unit test:

    System.Diagnostics.Debugger.Launch();
    
    0 讨论(0)
  • 2020-12-17 08:20

    One problem that I stumbled upon when trying to debug a test method was that it was private. Simply changing the method from private to public fixed my problem.

    I don't know why this is a problem, but it probably has something to do with the implementation of the [Test] attribute of NUnit.

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

    If you have [HostType("ASP.NET")], remove it and Test -> Debug -> Run your tests again

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

    Ensure [TestMethod] attribute is present for the method, [TestClass] is present for class.

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