I have a .NET 4.0 C# solution with a tests project which runs unit tests under NUnit. The NUnit binaries are v3.5.
I can run the tests perfectly well, but I can’t set breakpoints and single step in Visual Studio. I’m guessing this is caused by the mismatch in .NET versions. Is there a way to single step through a v4.0 tests assembly using NUnit for v3.5?
The problem is that unless you tell it otherwise, NUnit will spawn a subprocess to run tests when it determines it necessary. If you watch it in Process Explorer, you can see that "nunit-console.exe"* spawns "nunit-agent.exe"*. The Visual Studio debugger doesn’t automatically attach to child processes.
In this case, I believe the version mismatch is why it chooses to start a subprocess. The easiest way to work around this is to edit "nunit-console.exe.config"* to change the set of
<supportedRuntime>values. There should already be a comment there marking the line that you should comment out in order to force it to run as .NET 4.0:Once you change that, the first NUnit process will already be .NET 4.0 and it shouldn’t need to spawn a subprocess. If you want to be sure, specify
/process=Singleand NUnit will either run in a single process or fail immediately if it cannot.* – If you need to use the x86 versions, substitute: