Stepping through and debugging code in Unit tests

When using Microsoft.VisualStudio.TestTools.UnitTesting, go to 'Test' in the main menu of VS 2010, click submenu 'Debug' -> 'tests in current context'.

Right-clicking on the test-code and selecting 'run tests' will never start the debugger, not even when mode = debug.


Yes you can, thank you :)

To actually break on them you need to run your unit tests in Debug mode though.


Another solution...

You need to run and attach the debugger.

Set this line at the first line executed in your test (maybe in the test class constructor):

System.Diagnostics.Debugger.Launch();

Then when the debug window is open, chose Visual Studio.


It's far simpler in Visual Studio 2013. In Test Explorer, select the tests you wish to debug, right-click, and choose debug selected tests.

Enter image description here