How can i test that the code executes in debug mode.
Here is what i would like to do in pseudocode
if not debugMode then
Do something()
end if
Debug and analyze unit tests with Test ExplorerYou can use Test Explorer to start a debugging session for your tests. Stepping through your code with the Visual Studio debugger seamlessly takes you back and forth between the unit tests and the project under test.
Set breakpoints in source code To set a breakpoint in source code, click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.
Main objective of Testing is to find bugs and errors in an application which get missed during the unit testing by the developer. On other hand the main objective of Debugging is to find the exact root cause at code level to fix the errors and bugs found during the testing.
You can use Debugger.IsAttached to determine whether the program is being debugged.
If Not Debugger.IsAttached Then
DoSomething()
End If
EDIT If you always want to skip the DoSomething
code in the debug build, whether or not a debugger is being used, use conditional compilation with #If, something like this
#IF DEBUG Then
DoSomething()
#End If
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With