Visual Studio “Debug Unit Test” fails to hit breakpoints

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

提交回复
热议问题