zoukankan      html  css  js  c++  java
  • [翻译]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
  • 相关阅读:
    vue axios的使用
    html5 css写出一个实心三角形和空心三角行
    弹出新页面并使整个旧页面背景变暗功能的实现代码
    radio 单选按钮 选中多个
    搭建脚手架cli2.x环境
    页面滚动条位置触发事件
    DataGridView行号发生变化 使用的事件
    eclipse git 忽略文件
    eclipse git 分享项目到GitHub上
    eclipse git 创建新分支 合并分支 删除分支
  • 原文地址:https://www.cnblogs.com/kim01/p/3466086.html
Copyright © 2011-2022 走看看