2014-10-03 23 views
5

Böyle basit bir bölge nesne var çalışmaz:iOS testler

@interface Person : RLMObject 
@property NSString *name; 
@end 

RLM_ARRAY_TYPE(Person) 
  • Zaten benim test projesi için "Hedef Üyeliği" etkin

Şimdi realm.io ile bir şeyler bu şekilde test etmek:

#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]; 

    ...... 
} 

... ama ilk satırda Test çöker (Kişi * pers

Does 'objectClass RLMObject türetilmesi gerekir': nedeniyle yakalanmamış istisna 'RLMException', akla uygulamayı sonlandırılması aşağıdaki hata

*** birlikte); on = [[Kişi alloc] init] Herkes yanlış yaptığımı biliyor mu? Herhangi bir ipucu için minnettarım!

+0

Hey Marco, kodunuzun daha fazlasını paylaşır mısınız? Ben sadece bunu denedim ve iyi çalıştı https://dl.dropboxusercontent.com/u/10116/Screen%20Shot%202014-10-03%20at%2010.57.58%20AM.png – yoshyosh

+0

Merhaba hızlı cevap için teşekkürler yoshyosh. Normal proje hedefimde her şey gayet iyi çalışıyor ancak test hedefinde (birim testi) çalışmıyor. Yani kodunuzu bir XCTestCase'e kopyalamaya çalışırsanız, o da işe yarıyor mu? –

+1

Evet, her şey benim için geçer https://www.dropbox.com/s/a31qjgdqx1jjxot/Screen%20Shot%202014-10-03%20at%202.29.08%20PM.png?dl=0 Kodunuzu paylaşabilir misiniz? ? – yoshyosh

cevap

2

Aynı hatayı sahip ve sil, klon 4 saat sonra, temiz, benim açımdan çalışan olduğunu ... tekrarlayın bölmeleri yeniden yükleyin edildi:

Podfile

link_with 'MyProject', 'MyProjectTests' 

#common pods such as CocoaLumberjack 

pod 'Realm', '0.89.0' 

target 'MyProjectTests', exclusive: true do 
    pod 'Realm/Headers' 
end 

testdosyası

#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]; 
} 
+0

_pod 'Realm/Headers'_ yöntemi benim için çalıştı. – zim

İlgili konular