how to debug with xUnit?

I've not tested this but you should be able to attach visual studio to the xUnit GUI and debug from there.

From the Debug menu select 'attach to process', locate the name of the executable in the list and click attach. Set breakpoints in the unit test as required and run the test from the GUI. The breakpoint should be hit as expected.


In VS2015 and later, install the xunit.runner.visualstudio NuGet package. Then debugging is as easy as right-clicking on the test in the test explorer window. (Test-->Windows-->TestExplorer if you can't see it). You can also right-click anywhere in the code of the test and Run Test and Debug Test will be in the context menu. If your test is not showing up, be sure the class and method are both public.

enter image description here


In visual studio 2017, make sure that solution configuration is under 'Debug' mode. Under 'Release' mode it is not debugging.


I have failed in implementing all of the above, but the following worked for me: Before the lines where you want to debug add the following line (then run the test):

        System.Diagnostics.Debugger.Launch();

The drawback is that it will launch another instance of VS :).

Cheers!