Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
I have some methods in my codebase that utilize the #if DEBUG preprocessor directive to provide specialized behavior that differs between the debugging environment and the production environment. I...
#1: Initial revision
Unit Testing #define Directives in Visual Studio
I have some methods in my codebase that utilize the `#if DEBUG` preprocessor directive to provide specialized behavior that differs between the debugging environment and the production environment. I would like to ensure that I have unit tests that validate both of these paths. **Is there a way to do this in Visual Studio without needing to re-run the tests from a different environment?** Something like an Attribute that can be attached to the test method? MSTest or xUnit solutions would be preferred. I tried simply having a RowData/InlineData and using the method parameter to #define inside of an if block, but that is explicitly disallowed: ``` if (debugTestState) { #define DEBUG } else { #undef DEBUG } ``` ... results in: > CS1032: Cannot define/undefine preprocessor symbols after first token in file