Realm 上的测试用例(通过 CocoaPods 安装 Realm)

Test Case on Realm (Realm install by CocoaPods)

我正在使用 CocoaPods 安装 Realm。然后现在我需要为我的函数编写测试用例。 问题是编译找不到 Realm/Realm.h。 下面是我的测试用例。

#import <XCTest/XCTest.h>
#import "Bookmark.h"

@interface BookmarkTest : XCTestCase

@end

@implementation BookmarkTest
{
    Bookmark *bookmark;
}

- (void)setUp {
[super setUp];
bookmark = [[Bookmark alloc]init];
}
@end

下面是我的书签class

#import <Realm/Realm.h>
//error shown here:Realm/Realm.h file not found


RLM_ARRAY_TYPE(Bookmark)
@interface Bookmark : RLMObject

@property NSString *bId;
@property int type;
@property NSString *mallId;
@property NSString *storeId;
@property NSString *itemId;
@end

我的播客文件,

pod 'Realm'
pod 'Realm/Headers'

谢谢。

您还必须在 Podfile 中指定测试目标。 CocoaPods 0.39 之前的版本默认仅集成项目中的第一个目标。

子规范 Realm/Headers 仅适用于具有静态链接的测试目标。

鉴于您的测试目标,假设它被命名为 MyAppTests 已经链接到您的应用程序目标,它通常使用默认设置,您的 Podfile 应该如下所示:

target "MyApp" do
    pod "Realm"
end

target "MyAppTests" do
    pod "Realm/Test"
end