Unit testing class library using Realm.Net

Viewed 328

I'm developing a class library(RealmClassLibrary) which using Realm Xamarin(.NET). I want to test the library using xunit(RealmClassLibrary.Test). And I got a TypeInitializationException when the library code calls Realm.GetInstance(config)

This exception is not thrown when I embedded class library in Windows Application(RealmClassLibrary.Example).

How could I fix this problem? Is there best practice to unit test realm based project?

Any helps appreciated.

Simple regeneration code

https://github.com/engraphia/RealmClassLibrary

Error log

RealmClassLibrary.Tests.Class1Test.testMain [FAIL]
  System.TypeInitializationException : The type initializer for 'Realms.Realm' threw an exception.
  ---- System.DllNotFoundException : Unable to load DLL 'realm-wrappers': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
  Stack Trace:
       at Realms.Realm.GetInstance(RealmConfigurationBase config)
    \\RealmClassLibrary\RealmClassLibrary\MainClass.cs(14,0): at RealmClassLibrary.MainClass.Main()
    \\RealmClassLibrary\RealmClassLibrary.Tests\Class1Test.cs(16,0): at RealmClassLibrary.Tests.Class1Test.testMain()
    ----- Inner Stack Trace -----
       at Realms.NativeCommon.register_notify_realm_changed(NotifyRealmCallback callback)
       at Realms.Realm..cctor()

version

  • Visual Studio (windows)
    • 2015 update3
  • .NETFramework
    • v4.6.1
  • Realm Xamarin (.NET)
    • 1.5.0

project structure

  • RealmClassLibrary
    • target class library
  • RealmClassLibrary.Tests
    • unit test project
  • RealmClassLibrary.Example
    • windows application project
0 Answers
Related