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\
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):
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
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
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
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.