Stealth Rabbi
Stealth Rabbi

Reputation: 10346

Are there NUnit Test Case Attributes for specifying Configuration

I am writing an NUnit test that I want run only in the Release configuration. Is there an elegant way of doing this with a test case attribute? Right now, I am surrounding the entire function block with compiler directives:

I am using Nunit 2.5.6.10205.

#if !DEBUG
        [Test]
        public void MyReleaseOnlyTest()
        {
           // stuff
        }
#endif

Upvotes: 3

Views: 1545

Answers (2)

manojlds
manojlds

Reputation: 301037

Add the Ignore attribute in #if preprocessor, rather than the entire test method.

#if DEBUG
[Ignore("Only to be run in release")] 
#endif

http://msdn.microsoft.com/en-us/library/4y6tbswk.aspx

You can also use the Conditional attribute

[System.Diagnostics.Conditional("RELEASE")]

Upvotes: 3

Mike Two
Mike Two

Reputation: 46173

You could use the [Category] attribute. If you mark release only tests with [Category("Release")] then exclude that category in your normal test run and include it in you release run.

So now your test becomes

[Test]
[Category("Release")]
public void MyReleaseOnlyTest()
{
   // stuff
}

Upvotes: 6

Related Questions