Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a unit test run in DEBUG mode only?

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?

like image 882
Julien Poulin Avatar asked Oct 30 '09 11:10

Julien Poulin


1 Answers

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.

like image 140
C. Ross Avatar answered Sep 21 '22 14:09

C. Ross