IOS tests with realm.io do not work

I have a simple scope object:

@interface Person : RLMObject @property NSString *name; @end RLM_ARRAY_TYPE(Person) 
  • I have already enabled "Target Membership" for my test project.

Now I like to check something with realm.io as follows:

 #import <XCTest/XCTest.h> #import "Person.h" @interface PersonTests : XCTestCase @end @implementation PersonTests - (void)setUp {[super setUp];} - (void)tearDown {[super tearDown];} - (void)testFooBar { // !!! the test crashes right here!!!! Person *person = [[Person alloc] init]; person.name = @"foobar"; RLMRealm *realm = [RLMRealm defaultRealm]; [realm beginWriteTransaction]; [realm addObject:person]; [realm commitWriteTransaction]; ...... } 

... but the test fails in the first line (Person * person = [[Person alloc] init];) with the following error

*** Application termination due to an uncaught exception "RLMException", reason: "objectClass must be obtained from RLMObject"

Does anyone know what I'm doing wrong? I am grateful for any hint!

+5
source share
1 answer

I had the same error, and after 4 hours of uninstalling, cloning, cleaning, reinstalling modules, retrying ... that works for me:

Podfile

 link_with 'MyProject', 'MyProjectTests' #common pods such as CocoaLumberjack pod 'Realm', '0.89.0' target 'MyProjectTests', exclusive: true do pod 'Realm/Headers' end 

Testfile

 #import <UIKit/UIKit.h> #import <XCTest/XCTest.h> #import <Realm/Realm.h> #import "RealmObjectSubclass.h" - (void)setUp { [super setUp]; NSString *resourcePath = [NSBundle bundleForClass:[self.class]].resourcePath; NSString *testRealPath = [NSString stringWithFormat:@"%@.test", resourcePath]; [RLMRealm setDefaultRealmPath:testRealPath]; } 
+2
source

Source: https://habr.com/ru/post/1203954/


All Articles