如何在 STA 线程中运行 NUnit 测试? [英] How to run NUnit test in STA thread?
问题描述
我们正在将 WPF 应用程序移植到 .NET Core 3,预览版 5.一些 NUnit 测试需要在 STA 线程中运行.这怎么办?
We are in the process of porting a WPF app to .NET Core 3, preview 5. Some NUnit tests need to run in STA threads. How can this be done?
[STAThread]、[RequiresSTA]、...等属性都不起作用.这也不起作用:[程序集:RequiresThread(ApartmentState.STA)]
None of the attributes like [STAThread], [RequiresSTA], ... work. This also doesn't work: [assembly: RequiresThread(ApartmentState.STA)]
在 .NET Core 3 中似乎没有公开 Apparent 命名空间.
The Apparent namespace does not seem to be exposed in .NET Core 3.
有人这样做过吗?
推荐答案
ApartmentAttribute
在 NUnit 3.12 中首次为 .NET Standard 2.0 启用.
ApartmentAttribute
was first enabled for .NET Standard 2.0 in NUnit 3.12.
首先更新您的 NUnit 框架版本,然后使用 [Apartment(ApartmentState.STA)]
.
First update your version of the NUnit framework, then use [Apartment(ApartmentState.STA)]
.
这篇关于如何在 STA 线程中运行 NUnit 测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!