2013-02-13 77 views
1

我工作的OCUnit測試案例的OCUnit測試案例問題

- (NSDictionary*)Event:(EventBase*)event 
{ 
    [self doesNotRecognizeSelector:_cmd]; 
    return nil; 
} 

我發現這個方法來編寫測試用例

在我的測試用例類我傳遞事件值有效,對於無效和無上述方法

-(void)testEventNil{ 

NSDictionary *t_Dict; 
EventClass *t_EventClass = [[EventClass alloc]init]; 
t_Dict = [t_EventClass Event:nil]; 
STAssertNil (t_Dict, @"Return nil"); 
} 

-(void)testEventNil{ 

NSDictionary *t_Dict; 
NSMutableDictionary *invalid; 
[invalid setObject:@"1324" forKey @"Number"]; 
EventClass *t_EventClass = [[EventClass alloc]init]; 
t_Dict = [t_EventClass Event:]; 
STAssertNil (t_Dict, @"Return nil"); 
} 

-(void)testEventvalid{ 

NSDictionary *t_Dict; 
NSMutableDictionary *invalid; 
[invalid setObject:@"WorkNameEvent" forKey @"EventNameKey"]; 
EventClass *t_EventClass = [[EventClass alloc]init]; 
t_Dict = [t_EventClass Event:]; 
STAssertNotNil (t_Dict, @"Return nil"); 
} 

它給我的錯誤無法識別的選擇發送到實例

可以在任何一個建議我固定的問題

@All 預先感謝

回答

1

你的代碼中有多處錯誤。我無法理解它。

您正試圖測試旨在引發錯誤的方法。也許它打算被重寫?唯一可能的測試,因爲它現在是

EventClass *event = [EventClass new]; 
STAssertThrows([t_EventClass Event:nil],@"Should throw an error."); 

當你寫:t_Dict = [t_EventClass Event:];你不傳遞任何參數給Event:方法。

這不起作用或者:

NSMutableDictionary *invalid; 
[invalid setObject:@"WorkNameEvent" forKey @"EventNameKey"]; 

因爲你沒有初始化的字典。也就是說,

NSMutableDictionary *invalid = [NSMutableDictionary new]; 

在Objective-C的約定是使用駱駝名稱的方法和變量,在這種情況下event:代替Event:dic而是t_Dic

+0

這就是很多,也爲目標的約定規則C – kiran 2013-02-14 10:55:04

+0

歡迎您! – Jano 2013-02-14 18:37:41