Are there NUnit test case attributes to indicate configuration

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

I am using Nunit 2.5.6.10205.

#if !DEBUG [Test] public void MyReleaseOnlyTest() { // stuff } #endif 
+3
c # unit-testing nunit
source share
2 answers

You can use the [Category] attribute. If you flag tests for release only using [Category("Release")] , then exclude this category in your regular test run and include it in your release.

So now your test will become

 [Test] [Category("Release")] public void MyReleaseOnlyTest() { // stuff } 
+6
source share

Add the Ignore attribute to the #if preprocessor, not 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")] 
+3
source share

All Articles