[翻译]NUnit---RequiredAddin and RequiresMTA Attributes(十六)

RequiredAddinAttribute (NUnit 2.5)

  RequiredAddin特性用于提示一个程序集须要特殊的插件才能保证功能正常。若是没有安装插件,整个程序集会被标记为未运行。多线程

Note:Alpha-3版本,这个特性能够运用于类或方法。但这是受限制的,主要有2个缘由:less

  一、如因为遗漏了插件,那么这个方法或者类不被承认为一个测试,NUnit一直都不会处理它。测试

  二、若是这个方法或者类又不一样的插件处理,插件肯能没法识别这个特性ui

在下个版本中这个特性可能会被限制于程序集。this

Example

[assembly: RequiredAddin("MyTestFixtureAddin")]
[assembly: RequiredAddin("MyTestAddin")]
[assembly: RequiredAddin("MyDecoratorAddin")]

...

namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [MyTestFixture]
  public class MyTests
  {
    [MyTest]
    public void SomeTest()
    {
      ...
    }
  }
  
  [TestFixture, MyDecorator]
  public class MoreTests
  {
    [Test, MyDecorator]
    public void AnotherTest()
    {
      ...
    }
  }
}

 

RequiresMTAAttribute (NUnit 2.5)

  RequiresMTA特性能够应用与测试方法、类或者程序集,用于指定这些测试应该在多线程环境下运行。若是父类测试没有在多线程中运行那么它会建立一个新的进程。spa

Note:在测试方法你也能够使用RequiresMTA特性。尽管运行时只在执行程序集入口确认,许多用户但愿在测试上工做,因此咱们把它看成同义词。插件

Examples

// An MTA thread will be created and used to run
// all the tests in the assembly
[assembly:RequiresMTA]

...

// TestFixture requiring a separate thread
[TestFixture, RequiresMTA]
public class FixtureRequiringMTA
{
  // An MTA thread will be created and all
  // tests in the fixture will run on it
  // unless the containing assembly is
  // already running on an MTA Thread
}

[TestFixture]
public class AnotherFixture
{
  [Test, RequiresMTA]
  public void TestRequiringMTA()
  {
    // A separate thread will be created for this test
    // unless the containing fixture is already running 
    // in the MTA.
  }
}

See also...

  • RequiresThreadAttribute
  • RequiresSTAAttribute
相关文章
相关标签/搜索