NUnit Debugging Tests

I have a .NET 4.0 C # solution with a test project that runs unit tests under NUnit. NUnit binaries - v3.5.

I can do tests fine, but I can’t set breakpoints and one step in the visual studio. I assume that this is caused by an incorrect match in .NET versions. Is there a way to take one step through the assembly of v4.0 tests using nunit for v3.5?

+7
source share
5 answers

The problem is that unless you state otherwise, NUnit will create a subprocess to run the tests when it determines it. If you look at it in Process Explorer, you will see that "nunit-console.exe" * generates "nunit-agent.exe" *. The Visual Studio debugger does not automatically join child processes.

In this case, I believe the version mismatch is why he wants to start the subprocess. The easiest way to get around this is to edit "nunit-console.exe.config" * to change the set of <supportedRuntime> values. There should already be a comment indicating the line you should comment to make it work like .NET 4.0:

 <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> 

Once you change this, the first NUnit process will already be .NET 4.0, and it will not need to create a subprocess. If you want to be sure, specify /process=Single , and NUnit will either be launched in the same process, or it will immediately work if it cannot.

* - If you need to use x86 versions, replace:

 nunit-console.exe -> nunit-console-x86.exe nunit-agent.exe -> nunit-agent-x86.exe nunit-console.exe.config -> nunit-console-x86.exe.config 
+21
source

In case this is useful for someone I know, it's 4 years old, but I followed the answers here and they were helpful. Although my answer is for a different version of NUnit, however, for someone like me who just discovered this, I installed NUnit and NUnit Console through the Manage NuGet Packages ... (1st and 3rd options in the screenshot) enter image description here and thus set up the Debug tab of my test project (see the following screenshot below) in the VS2015 Community version to run nunit3-console.exe, which is located in the \ packages folder, which is automatically created when the "NUnit Console" is installed and for the arguments I added the dll library for the test library, and the command line switches for the wait (which offers the developer “Press any key to close” so you can see the result), and, more importantly, the process that automatically attaches your .NET test library your splash points fall .

enter image description here

Note to launch the NUnit3 console application, you install the test project as a launch project.

+3
source

Another option is to use http://testdriven.net/ to run your tests through Visual Studio, you can put a breakpoint on the test and right-click → run tests → with the debugger.

+2
source

Resharper allows you to run your unit tests during debugging. But I do not think you can do the same with Visual Studio. Try installing a trial version of Resharper, and then try debugging the tests.

+1
source

I have no doubt about the console application, but you should find that you can start the GUI version of NUnit manually and then connect to the nunit-agent process from the debugger in Visual Studio.

+1
source

All Articles