Nunit not hitting breakpoints in test project class library (VS2012)

In my case a line of code seemed to execute a never-ending loop, which made it impossible to reach the breakpoint.

Solution: Put a breakpoint in the beginning of the debug method in order to check for this error!


Instead of running your tests, try debugging your tests

enter image description here


My test code was compiled in .Net 4.5 and was using the Nunit2.6.1.

The breakpoints were not getting hit if I had only made the test project's debug option->start external program->nunit-86x.exe and give the .dll name to be the command line argument.

This starts off the Nunit exe but without breakpoints.

1) To solve this go to

C:\Program Files (x86)\NUnit 2.6.1\bin

2) Search for nunit-x86.exe.config or if you plan to use the nunit.exe then open nunit.exe.config.

3) Open the fine in notepad and search for the line

<startup useLegacyV2RuntimeActivationPolicy="true">
<!-- Comment out the next line to force use of .NET 4.0 -->
<supportedRuntime version="v2.0.50727" />
<supportedRuntime version="v4.0.30319" />
</startup>

4) Remove the line of supported Runtime version=v2.0.50727 and save the file(open in administrator mode by opening notepad in admin by right click and open as admin).

5) Rebuild project the run your test code's debug session. The breakpoints will be hit.


For anyone else having this issue: check if you are building in Release mode.

I had this problem with NUnit 3.7.0, and dotnet core 1.0, and VS 2017. It turned out that I was building in Release mode. Building in Debug mode fixed the issue.