我是 MAUI 的初学者。我想在创建 MAUI 控件的 NUnit 中测试一些代码。
我将测试简化为以下简短的测试:
public void MyTest()
{
Microsoft.Maui.Controls.ListView result = new(ListViewCachingStrategy.RetainElement);
}
我得到以下异常:
BindableObject was not instantiated on a thread with a dispatcher nor does the current application have a dispatcher.
我觉得正确的方式应该是使用调度器。但是应该怎么做呢?
如果我使用下面的代码,它总是空的。
DispatcherProvider.Current.GetForCurrentThread();
Dispatcher.GetForCurrentThread();
目前代码是被NUnit-Test调用的,后面应该也会被app调用