Testing a Realm-based framework in Swift

1

I want to encapsulate some of the functionality of my app in a dynamic framework. In this framework, I want to use Realm to persist some of the data.

Naturally, the way to test frameworks is with XCTest. However, any use of Realm aside from the import statement in my XCTestCase subclasses, and I get this bizarre error:

Test failure

I included Realm.framework and RealmSwift.framework in my framework using a Copy Files phase. I tried not doing that, as well. I've tried linking Realm and RealmSwift in my test target, and not linking them. I've tried everything I can think of. I don't know what's happening.

This is a framework that, at the moment, does almost nothing. There's an Object subclass, with no properties at all, and there's a test case, which simply sets up the Realm configuration for testing, and then does nothing else:

Realm.Configuration.defaultConfiguration.inMemoryIdentifier = "TestFrameworkTests"

as recommended in the documentation.

Doing literally anything with the Realm object, or any Realm classes, causes this weird error. And it gets a little bit weirder:

1/02/2016 6:50:44.784 PM com.apple.debugserver-@(#)PROGRAM:debugserver  PROJECT:debugserver-340.4.119
[80894]: 1 +0.000000 sec [13bfe/1303]: error: ::read ( 3, 0x700000080a40, 1024 ) => -1 err = Bad file descriptor (0x00000009)

Bad file descriptor. Where is that coming from? Is this an Xcode bug? If so – has anyone found a workaround?

Here's a copy of the framework, if you want to mess around with it: https://www.dropbox.com/s/q1708dw7uuaakoo/TestFramework.zip?dl=0

ios
swift
realm
xctest
asked on Stack Overflow Feb 1, 2016 by Morgan Harris

1 Answer

0

Alright, this was solved by compiling from source. There's clearly some kind of bug in Realm that has since been fixed on GitHub but wasn't fixed in the binary release.

answered on Stack Overflow Feb 2, 2016 by Morgan Harris

User contributions licensed under CC BY-SA 3.0