Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing if code executes in debug mode

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
like image 265
OrElse Avatar asked Aug 12 '09 11:08

OrElse


People also ask

Can we debug unit test?

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.

How do you test a breakpoint in VS code?

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.

What is difference between debugging and unit testing?

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.


1 Answers

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
like image 157
MarkJ Avatar answered Sep 20 '22 23:09

MarkJ