Xamarin 中 Realm 的单元测试 iOS
Unit testing of Realm in Xamarin iOS
Xamarin iOS 本机应用程序。我必须为 Realm api 编写单元测试。它是具有过滤数据能力的层。它可以包含复杂的 Linq 查询,因此有必要进行测试。
例如,方法:
Task<List<T>> Get(int count, int type, int? id);
正在创建 NUnit 测试我需要获取 Realm 对象:
var realm = Realm.GetInstance(new InMemoryConfiguration("test"));
但出现异常:
System.TypeInitializationException : The type initializer for 'Realms.SharedRealmHandle' threw an exception.
----> System.DllNotFoundException : realm-wrappers assembly:<unknown assembly> type:<unknown type> member:(null)
at Realms.InMemoryConfiguration.CreateRealm (Realms.Schema.RealmSchema schema) [0x0003e] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Configurations\InMemoryConfiguration.cs:62
at Realms.Realm.GetInstance (Realms.RealmConfigurationBase config, Realms.Schema.RealmSchema schema) [0x0003c] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Realm.cs:136
at Realms.Realm.GetInstance (Realms.RealmConfigurationBase config) [0x00000] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Realm.cs:81
at UnitTestREALM.TransactionsRealmApiTest.RealmApi () [0x00001] in /Users/user/Projects/myApp/UnitTestREALM/TransactionsRealmApiTest.cs:26
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395
--DllNotFoundException
at (wrapper managed-to-native) Realms.SynchronizationContextEventLoopSignal.install_eventloop_callbacks(Realms.SynchronizationContextEventLoopSignal/get_eventloop,Realms.SynchronizationContextEventLoopSignal/post_on_event_loop,Realms.SynchronizationContextEventLoopSignal/release_eventloop)
at Realms.SynchronizationContextEventLoopSignal.Install () [0x0003b] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Native\SynchronizationContextEventLoopSignal.cs:122
at Realms.NativeCommon.Initialize () [0x00112] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Native\NativeCommon.cs:91
at Realms.SharedRealmHandle..cctor () [0x00000] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Handles\SharedRealmHandle.cs:128
所以,重点是我无法创建 Realm 实例。
是否需要启动 iphone 模拟器才能使用 Realm?
是否有可能为 Realm 创建单元测试?
或者应该是某种自动测试?
正如我发现的那样,解决方案是 iOS 单元测试应用程序(解决方案 -> 添加 -> 新项目 -> iOS -> 测试 -> 单元测试应用程序)。
缺点很少,但可以测试 Realm。下一个挑战是 运行 它并使用 TeamCity 获得结果。
Xamarin iOS 本机应用程序。我必须为 Realm api 编写单元测试。它是具有过滤数据能力的层。它可以包含复杂的 Linq 查询,因此有必要进行测试。 例如,方法:
Task<List<T>> Get(int count, int type, int? id);
正在创建 NUnit 测试我需要获取 Realm 对象:
var realm = Realm.GetInstance(new InMemoryConfiguration("test"));
但出现异常:
System.TypeInitializationException : The type initializer for 'Realms.SharedRealmHandle' threw an exception.
----> System.DllNotFoundException : realm-wrappers assembly:<unknown assembly> type:<unknown type> member:(null)
at Realms.InMemoryConfiguration.CreateRealm (Realms.Schema.RealmSchema schema) [0x0003e] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Configurations\InMemoryConfiguration.cs:62
at Realms.Realm.GetInstance (Realms.RealmConfigurationBase config, Realms.Schema.RealmSchema schema) [0x0003c] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Realm.cs:136
at Realms.Realm.GetInstance (Realms.RealmConfigurationBase config) [0x00000] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Realm.cs:81
at UnitTestREALM.TransactionsRealmApiTest.RealmApi () [0x00001] in /Users/user/Projects/myApp/UnitTestREALM/TransactionsRealmApiTest.cs:26
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395
--DllNotFoundException
at (wrapper managed-to-native) Realms.SynchronizationContextEventLoopSignal.install_eventloop_callbacks(Realms.SynchronizationContextEventLoopSignal/get_eventloop,Realms.SynchronizationContextEventLoopSignal/post_on_event_loop,Realms.SynchronizationContextEventLoopSignal/release_eventloop)
at Realms.SynchronizationContextEventLoopSignal.Install () [0x0003b] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Native\SynchronizationContextEventLoopSignal.cs:122
at Realms.NativeCommon.Initialize () [0x00112] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Native\NativeCommon.cs:91
at Realms.SharedRealmHandle..cctor () [0x00000] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Handles\SharedRealmHandle.cs:128
所以,重点是我无法创建 Realm 实例。
是否需要启动 iphone 模拟器才能使用 Realm?
是否有可能为 Realm 创建单元测试?
或者应该是某种自动测试?
正如我发现的那样,解决方案是 iOS 单元测试应用程序(解决方案 -> 添加 -> 新项目 -> iOS -> 测试 -> 单元测试应用程序)。 缺点很少,但可以测试 Realm。下一个挑战是 运行 它并使用 TeamCity 获得结果。