c# - 如何在 STAThread 模式下运行单元测试?

标签 c# nunit sta

我想测试一个使用剪贴板 (WindowsForms) 的应用程序,我的单元测试中也需要剪贴板。为了使用它,它应该在 STA 模式下运行,但是由于 NUnit TestFixture 没有 main 方法,我不知道在哪里/如何注释它。

最佳答案

如果你使用的是nunit 2.5+,你可以在类中使用新的RequiresSTAAttribute

[TestFixture, RequiresSTA]

或汇编级。

[assembly:RequiresSTA]

不需要配置文件。查看: http://www.nunit.org/index.php?p=requiresSTA&r=2.5

关于c# - 如何在 STAThread 模式下运行单元测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2434067/

相关文章:

c# - 在另一个线程中打开第二个 WPF 窗口?

c# - Linq/Enumerable Any Vs 包含

c# - .NET Core SSL - 模板仅在浏览器中显示 PR_CONNECT_RESET_ERROR (Firefox)

c# - MVC : is there a definitive answer as to where business logic belongs?

c# - 使用可执行路径打开文件的 nUnit 测试函数

c# - 在 C# 中测试类型安全枚举模式

javascript - 将值 "9:00 AM"转换为类型“System.TimeSpan”时出错

c# - 使用 Rhino Mocks 对 NpgsqlCommand 进行单元测试

multithreading - 单线程单元中的工作流程 4.0?

c# - 将 Keith Hill 的 PowerShell Get-Clipboard 和 Set-Clipboard 转换为 PSM1 脚本