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

[翻译]NUnit---RequiresSTA and RequiresThread Attributes(十七)的更多相关文章

  1. [翻译]NUnit---Action Attributes(八)

    Attributes NUnit 1.0使用传统的基于继承和命名约定来识别测试.从2.0开始NUnit使用自定义特性来实现. 因为NUnit的test fixtures不是从框架类库继承,所以开发人员 ...

  2. 最适合入门的Laravel中级教程(三)表单验证

    做开发有个原则是永远不能信任用户输入的数据: 即便前端已经做了验证: 在后端 php 也必须要再次验证: laravel 为表单验证提供了强大且简单的方案: 创建示例路由: routes/web.ph ...

  3. [翻译]NUnit---Property and Random Attributes(十四)

    小记:由于工作琐碎,没得心情翻译而且也在看<CLR vis C#>,所以断更了差不多5个月,现在继续翻译,保证会翻译完成,不会虎头蛇尾. 另:NUnit已经更新到2.6.3版本,虽然正在开 ...

  4. Gradle 1.12用户指南翻译——第四十七章. Build Init 插件

    本文由CSDN博客貌似掉线翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...

  5. Gradle 1.12 翻译——第十七章. 从 Gradle 中调用 Ant

    有关其他已翻译的章节请关注Github上的项目:https://github.com/msdx/gradledoc/tree/1.12,或访问:http://gradledoc.qiniudn.com ...

  6. Gradle 1.12用户指南翻译——第二十七章. Ear 插件

    其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Github上的地址: https://g ...

  7. Gradle 1.12用户指南翻译——第三十七章. OSGi 插件

    本文由CSDN博客万一博主翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...

  8. [翻译]NUnit---SetUp and SetUpFixture and Suite Attributes(十九)

    SetUpAttribute (NUnit 2.0 / 2.5) 本特性用于TestFixture提供一个公共的功能集合,在呼叫每个测试方法之前执行.同时也用在SetUpFixture中,SetUpF ...

  9. 第十七周翻译-SQL Server中事务日志管理的阶梯,级别5:以完全恢复模式管理日志

    SQL Server中事务日志管理的阶梯,级别5:以完全恢复模式管理日志 作者:Tony Davis,2012/01/27 翻译:赖慧芳 译文: 该系列   本文是Stairway系列的一部分:SQL ...

随机推荐

  1. 超薄二维Mo2C晶体

    记者今天从中国科学院金属研究所获悉,该所沈阳材料科学国家(联合)实验室先进炭材料研究部任文才研究组在大尺寸高质量二维过渡族金属碳化物晶体的制备与物性研究方面取得了重要突破.相关成果日前在<自然— ...

  2. MVVM 的理解

    MVVM 是 Model - View - ViewModel 的缩写 可以看到他和之前的MVC很像,的确有人称之为一个加强优化版的MVC. 是一种模块化开发代码分层的思想或者框架! MVVM 的优点 ...

  3. 源码包的解压 .tar.gz /.tar.bz2的解压

    解压方式如下: .tar.gz     格式解压为          tar   -zxvf   xx.tar.gz .tar.bz2   格式解压为          tar   -jxvf    ...

  4. Python staticmethod() 函数

    Python staticmethod() 函数  Python 内置函数 python staticmethod 返回函数的静态方法. 该方法不强制要求传递参数,如下声明一个静态方法: class ...

  5. centos安装Python插件后找不到对应的插件ModuleNotFoundError: No module named*

    题记 在之前的文章中,我在centos服务器装了python3并且给python与pip建立了软链,利用git上传代码到centos服务器之后利用终端运行app.py的时候会报错. 报错: [root ...

  6. Spring整合JMS——事务管理

    Spring提供了一个JmsTransactionManager用于对JMS ConnectionFactory做事务管理.这将允许JMS应用利用Spring的事务管理特性.JmsTransactio ...

  7. ubuntu系统:插入优盘read-only file system

    http://sharadchhetri.com/2013/12/19/how-to-fix-read-only-usb-pen-drive-in-ubuntu/ To fix USB pen dri ...

  8. [SoapUI] Datasink怎么显示每次循环的结果

    https://www.soapui.org/reporting/the-report-datasink.html

  9. JAVA Get UUID

    UUID是通用唯一标识码(Universally Unique Identifier),通过开源软件基金会(OSF)设立的一种算法生成.它的主要作用就是保证生成的字符串在同一时空中所有机器上都是唯一的 ...

  10. Executor(一)ExecutorService 线程池

    Executor(一)ExecutorService 线程池 本篇主要涉及到的是 java.util.concurrent 包中的 ExecutorService.ExecutorService 就是 ...