Are there NUnit Test Case Attributes for specifying Configuration

半腔热情 提交于 2019-12-18 08:58:10

问题


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

回答1:


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
}



回答2:


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")]


来源:https://stackoverflow.com/questions/5805464/are-there-nunit-test-case-attributes-for-specifying-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!