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


    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
  • 相关阅读:
    第十一周项目6-回文&素数(一)
    第十一周项目1-函数版星号图(三) .
    囚徒困境 For BBasic
    第十一周项目5-当年第几天
    第十一周项目4-特殊三位数
    第十一周项目3-程序的多文件组织
    第十一周项目2-求最大公约数
    第十一周项目1-函数版星号图(二)
    第十一周项目1-函数版星号图(一)
    第十周-囚徒困境
  • 原文地址:https://www.cnblogs.com/kim01/p/3464361.html
Copyright © 2020-2023  润新知