• [翻译]NUnit---RequiresSTA and RequiresThread Attributes(十七)


    RequiresSTAAttribute (NUnit 2.5)

      RequiresSTA特性用于测试方法、类、程序集中指定测试应该在单线程中运行。如果父测试不在单线程中运行则会创建一个新的线程。

    Note:

      在测试方法上也可以使用STAThread特性。尽管运行时指挥在执行程序集的入口识别这个特性,但是许多用户希望再测试上工作,所以我们把它作为一个同义词。

    Examples

    // An STA thread will be created and used to run
    // all the tests in the assembly
    [assembly:RequiresSTA]
    
    ...
    
    // TestFixture requiring a separate thread
    [TestFixture, RequiresSTA]
    public class FixtureRequiringSTA
    {
      // An STA thread will be created and all
      // tests in the fixture will run on it
      // unless the containing assembly is
      // already running on an STA Thread
    }
    
    [TestFixture]
    public class AnotherFixture
    {
      [Test, RequiresSTA]
      public void TestRequiringSTA()
      {
        // A separate thread will be created for this test
        // unless the containing fixture is already running 
        // in the STA.
      }
    }

    See also...

    • RequiresThreadAttribute
    • RequiresMTAAttribute

    RequiresThreadAttribute (NUnit 2.5)

      RequiresThread特性指示一个测试方法、类或者程序集应该在一个独立的线程中运行。还可以在构造函数中指定需要的线程。

    Note:这个特性经常和ApartmentState参数一起使用,配合使用来创建一个新的线程。如果不合适用ApartmentState来创建线程,还还可以使用RequiresSTA特性或者RequiresMTA特性。

    Examples

    // A thread will be created and used to run
    // all the tests in the assembly
    [assembly:RequiresThread]
    
    ...
    
    // TestFixture requiring a separate thread
    [TestFixture, RequiresThread]
    public class FixtureOnThread
    {
      // A separate thread will be created and all
      // tests in the fixture will run on it.
    }
    
    [TestFixture]
    public class AnotherFixture
    {
      [Test, RequiresThread]
      public void TestRequiringThread()
      {
        // A separate thread will be created for this test
      }
      
      [Test, RequiresThread(ApartmentState.STA)]
      public void TestRequiringSTAThread()
      {
        // A separate STA thread will be created for tnis test.
      }
    }

    See also...

    • RequiresSTAAttribute
    • RequiresMTAAttribute
  • 相关阅读:
    POJ
    FZU
    HDU
    HDU
    HDU
    HDU
    Educational Codeforces Round 84 E. Count The Blocks
    B Boundary(由弦求圆)
    D. Maximum Sum on Even Positions(翻转1次,求最大偶数位和)
    E. DeadLee(思维,拓扑图处理)
  • 原文地址:https://www.cnblogs.com/kim01/p/3466086.html
Copyright © 2020-2023  润新知