As stated, unit tests are designed to run without interaction.
However, you can debug unit tests, just like any other code. The easiest way is to use the Debug button in the Test Results tab.
Being able to debug means being able to use breakpoints. Being able to use breakpoints, then, means being able to use Tracepoints, which I find extremely useful in every day debugging.
Essentially, Tracepoints allow you to write to the Output window (or, more accurately, to standard output). Optionally, you can continue to run, or you can stop like a regular breakpoint. This gives you the "functionality" you are asking for, without the need to rebuild your code, or fill it up with debug information.
Simply add a breakpoint, and then right-click on that breakpoint. Select the "When Hit..." option:
Which brings up the dialog:
A few things to note:
- Notice that the breakpoint is now shown as a diamond, instead of a sphere, indicating a trace point
- You can output the value of a variable by enclosing it like {this}.
- Uncheck the "Continue Execution" checkbox to have the code break on this line, like any regular breakpoint
- You have the option of running a macro. Please be careful - you may cause harmful side effects.
See the documentation for more details.
Dump
extension method that outputs the object's contents into the console, making things so much easier to debug. i.imgur.com/MEZwy7X.png – DharmaTurtle