Is it wise to leave Trace.Assert
and Debug.Assert
statements in code that is "stable" and which has been moved into Test and Production environments?
If so, how do these assertion statements help? Isn't it sufficient to have Guard classes, etc. check for exception conditions and raise exceptions as appropriate?
Debug.Assert statements will be ignored unless you have the DEBUG compilation constant defined, which by default happens when you compile in the "debug" configuration and not in the "release" configuration. Indeed, the Debug class is inteded to be used only in testing environments, where you are supposed to catch all (or at least most) of the bugs that would cause Debug.Assert to fail.
Trace.Assert works the same way, except that the compilation constant that must exist is TRACE, which by default exists in both "debug" and "release" configurations. It may make sense to have trace assertions in release code, but it is usually preferable to make them do something else than the default behavior of the method (which just displays a message box with the stack trace). You can achieve this by configuring a custom trace listener for the Trace class; see the method documentation for more details.
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