简体   繁体   English

Nunit 3.12.0 在 WPF 视图模型单元测试中缺少 [RequiresSTA]。 调用线程必须是 STA

[英]Nunit 3.12.0 missing [RequiresSTA] in WPF view model unit test. The calling thread must be STA

After update Nunit from version v2.6.3 to 3.12.0.将 Nunit 从 v2.6.3 更新到 3.12.0 后。 my unit stopped passing.我的单位停止通过。 The problem occurs in unit tests with RequiresSTAAttribute witch could not be found after update.该问题发生在单元测试中,更新后无法找到 RequiresSTAAttribute 女巫。

[Test]
[RequiresSTA]
public void When_Smart_Motion_Activity_Is_Selected_The_Values_Are_Valid()
{
     SomeViewModel vm = ViewModelHelper.CreateDefaultViewModel();
     ...
}

With attribute removed test failed with following exception:删除属性后测试失败,出现以下异常:

System.InvalidOperationException : The calling thread must be STA, because many UI components require this. System.InvalidOperationException :调用线程必须是 STA,因为许多 UI 组件需要这样做。 at System.Windows.Input.InputManager..ctor() at System.Windows.Input.InputManager.GetCurrentInputManagerImpl() at System.Windows.Input.KeyboardNavigation..ctor() at System.Windows.FrameworkElement.FrameworkServices..ctor() at System.Windows.FrameworkElement.EnsureFrameworkServices() at System.Windows.FrameworkElement..ctor() at System.Windows.Controls.Panel..ctor() at System.Windows.Controls.Canvas..ctor() at project..... :line xyz在 System.Windows.Input.InputManager..ctor() 在 System.Windows.Input.InputManager.GetCurrentInputManagerImpl() 在 System.Windows.Input.KeyboardNavigation..ctor() 在 System.Windows.FrameworkElement.FrameworkServices..ctor( ) 在 System.Windows.FrameworkElement.EnsureFrameworkServices() 在 System.Windows.FrameworkElement..ctor() 在 System.Windows.Controls.Panel..ctor() 在 System.Windows.Controls.Canvas..ctor() 在项目..... :line xyz

Is there any suggested workaround or replacement for [RequiresSTA] that works for 3.12.0 ?是否有任何建议的解决方法或替代 [RequiresSTA] 适用于 3.12.0 ?

You can use:您可以使用:

[Test]
[Apartment(ApartmentState.STA)]
public void When_Smart_Motion_Activity_Is_Selected_The_Values_Are_Valid()
{
     SomeViewModel vm = ViewModelHelper.CreateDefaultViewModel();
     ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM