Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c Realm抛出空单元测试异常_Objective C_Swift_Unit Testing_Realm - Fatal编程技术网

Objective c Realm抛出空单元测试异常

Objective c Realm抛出空单元测试异常,objective-c,swift,unit-testing,realm,Objective C,Swift,Unit Testing,Realm,在Objective-C项目中,我们开始用Swift编写新的单元测试。我刚刚尝试创建成功保存已解析JSON结果的第一个单元测试。但是,由于以下错误,测试在setup()期间已失败: [ProjectTests.Project testInitializingOverlayCollectionCreatesAppropriateRealmObjects] : failed: caught "NSInvalidArgumentException", "+[RLMObjectBase ignoredP

在Objective-C项目中,我们开始用Swift编写新的单元测试。我刚刚尝试创建成功保存已解析JSON结果的第一个单元测试。但是,由于以下错误,测试在setup()期间已失败:

[ProjectTests.Project testInitializingOverlayCollectionCreatesAppropriateRealmObjects] : failed: caught "NSInvalidArgumentException", "+[RLMObjectBase ignoredProperties]: unrecognized selector sent to class 0x759b70
显然,它试图在
RLMObjectBase
类上执行
ignoredProperties
,但该方法尚未实现。我不知道这是怎么发生的,因为除了创建一个带有随机内存标识符的
RLMRealms
对象之外,我还没有初始化任何东西

项目测试。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)
    }

}
如报告中所述

避免在测试目标中链接领域和测试代码

ProjectTests
目标中移除王国吊舱,世界就万事大吉了


更新:此答案已过时。正如@rommex在评论中提到的,遵循当前的领域安装文档应该将其链接到您的模块和测试目标,而不会出现问题。但是,我没有检查这一点。

这个答案现在已经过时,而且是错误的(Realm 4.x),正如文档所述:
在您的pod文件中,添加使用框架!并将“RealmSwift”放入您的主要目标和测试目标。
@rommex感谢您的评论。虽然我自己没有检查过,但我确实更新了我的答案,向其他人指出了这一点。
#import <Realm/Realm.h>
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '7.1'

def shared_pods
    pod 'Realm', '0.95.0'
end

target 'Project' do
    shared_pods
end    

target 'ProjectTests' do
    shared_pods
end