I have a unit test that tests if an Exception is throw, but this Exception is only throw in Debug mode (via the [Conditional("DEBUG")] Attribute). If I run this test in Release mode, it fails. I tried to apply the same Attribute on the test but it's no taken into account.
How can I exclude a test in Release mode? Does it even make sense to run unit tests in Release mode or should I stick to Debug mode?
As for most of your question, it depends somewhat on what unit testing tool your using. However, in general what you want are preprocessor directives
//C#
#ifndef DEBUG
//Unit test
#endif
Perhaps for your situation
//C# - for NUnit
#if !DEBUG
[Ignore("This test runs only in debug")]
#endif
But as to whether to leave unit tests in the release version? I'd give a resounding NO. I'd suggest moving all your unit tests into it's own project and NOT including this in your releases.
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