mardi 2 février 2016

Realm throws exception with empty unit test

In an Objective-C project, we started writing our new Unit Tests in Swift. I'm just now trying to create our first Unit Test of successfully saving the results of a parsed JSON. However, the test already fails during setup() due to the following error:

[ProjectTests.Project testInitializingOverlayCollectionCreatesAppropriateRealmObjects] : failed: caught "NSInvalidArgumentException", "+[RLMObjectBase ignoredProperties]: unrecognized selector sent to class 0x759b70

So apparently it tries to execute ignoredProperties on the RLMObjectBase class, and that method isn't implemented yet. Not sure how this happens, because I have yet to initialise anything, beyond creating a RLMRealms object with a random in-memory identifier.

ProjectTests.swift

import XCTest

class ProjectOverlayCollectionTests: XCTestCase {

    var realm: RLMRealm!

    override func setUp() {
        super.setUp()

        // Put setup code here. This method is called before the invocation of each test method in the class.
        let realmConfig = RLMRealmConfiguration()
        realmConfig.inMemoryIdentifier = NSUUID().UUIDString
        do {
            realm = try RLMRealm(configuration: realmConfig) // <-- Crashes here.
        }
        catch _ as NSError {
            XCTFail()
        }
    }

    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    func testInitializingOverlayCollectionCreatesAppropriateRealmObjects() {
        XCTAssertTrue(true)
    }

}

Project-Bridging-Header.h

#import <Realm/Realm.h>

Podfile

source 'http://ift.tt/1czpBWo'
platform :ios, '7.1'

def shared_pods
    pod 'Realm', '0.95.0'
end

target 'ProjectTests' do
    shared_pods
end

Aucun commentaire:

Enregistrer un commentaire