【问题标题】:Unit testing of Realm in Xamarin iOSXamarin iOS 中 Realm 的单元测试
【发布时间】:2020-11-04 10:53:02
【问题描述】:

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 实例的要点。
与 Realm 一起使用是否需要启动的 iphone 模拟器? 是否有可能为 Realm 创建单元测试? 还是应该是某种自动测试?

【问题讨论】:

    标签: c# ios xamarin realm nunit


    【解决方案1】:

    我发现,解决方案是 iOS 单元测试应用程序(解决方案 -> 添加 -> 新项目 -> iOS -> 测试 -> 单元测试应用程序)。 缺点很少,但可以测试 Realm。下一个挑战是运行它并使用 TeamCity 获得结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-09
      • 1970-01-01
      • 1970-01-01
      • 2017-08-13
      • 1970-01-01
      相关资源
      最近更新 更多