我有一个包含三个项目的WinUI-3解决方案:后端和ViewModels的类libary,通过NUnit进行的单元测试,以及一个WinUI-3应用程序。
所有通过的测试都很正常,直到我在一个ViewModel方法中调用了ViewModel (从ViewModel构造函数中调用),现在该ViewModel的所有测试都失败了:
System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> System.Runtime.InteropServices.COMException : Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))
Stack Trace:
RuntimeType.CreateInstanceOfT()
Activator.CreateInstance[T]()
WeakLazy`1.get_Value()
_IColorsStatics.get_Instance()
Colors.get_Transparent()
MainViewModel.ctor(IServiceProvider provider) line 58
MainViewModelTests.Constructor_SetsCachedSortedColumn_ToLTV() line 64
--COMException
BaseActivationFactory.ctor(String typeNamespace, String typeFullName)
_IColorsStatics.ctor()
RuntimeType.CreateInstanceOfT()它看起来像一个依赖注入问题,有任何想法如何绕过这一点,或者NUnit只是不支持WinUI-3?
发布于 2022-03-22 14:44:20
您需要创建一个应用程序,按照描述的这里在UI线程上运行测试。
这样做的目的是为了使视图模型“不受WinUI特定逻辑的影响”,并在一个简单的单元测试项目中单独测试这些逻辑。
https://stackoverflow.com/questions/71533431
复制相似问题