代码改变世界

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

2013-12-09 08:49  Max蚊子  阅读(789)  评论(0编辑  收藏  举报

RequiredAddinAttribute (NUnit 2.5)

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

Note:Alpha-3版本,这个特性可以运用于类或方法。但这是受限制的,主要有2个原因:

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

  2、如果这个方法或者类又不同的插件处理,插件肯能无法识别这个特性

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

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特性可以应用与测试方法、类或者程序集,用于指定这些测试应该在多线程环境下运行。如果父类测试没有在多线程中运行那么它会创建一个新的进程。

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

 

网站:feiger.cn         飞鸽博客,关注互联网、站长圈的程序员博客!