I'm writing a library, and behaviour of it differs based on mode if it's debug or release. I want to write a unit-tests TestDebugBehaviour
and TestReleaseBehaviour
. Is it possible to setup tests to run in debug/release mode?
I think you should be able to do this with preprocessor directives. I am using xunit in my examples below; you will probably have to decorate your test method with a different attribute.
This test should only execute in debug mode.
#if DEBUG
[Fact]
public void ThisIsATestThatWillOnlyRunInDebugMode()
{
throw new Exception("I am running in debug mode.");
}
#endif
This test does not exactly run in release mode specifically, it just runs in any mode except debug mode but that is usually good enough.
#if !DEBUG
[Fact]
public void ThisIsATestThatWillNotRunInDebugMode()
{
throw new Exception("I am running in in something other than debug mode.");
}
#endif
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