2012-11-13 40 views
0

我正在爲返回NSMutableAttributedString的方法中的「if」語句編寫單元測試,並且出現一些錯誤。在NSMutableAttributedString上設置期望值

爲IF語句實際代碼:

if (conditionIsTrue) 
    { 
     return [[NSMutableAttributedString alloc] initWithString:NSLocalizedStringWithDefaultValue(@"ABC", 
                            @"ABCLibrary", 
                            [NSBundle bundleWithName:@"ABCLibraryResources"], 
                            @"No ABC", 
                            @"No ABC String") 
                 attributes:[self methodA]]; 
    } 

單元測試:

ControllerA *controller = [[ControllerA alloc] init]; 
id mockController = [OCMockObject partialMockForObject:controller]; 

NSMutableAttributedString *temp = [[NSMutableAttributedString alloc] initWithString:NSLocalizedStringWithDefaultValue(@"ABC", 
                            @"ABCLibrary", 
                            [NSBundle bundleWithName:@"ABCLibraryResources"], 
                            @"No ABC", 
                            @"No ABC String") 
                 attributes:[self methodA]]; 

    [[mockController expect] temp]; 

錯誤:

No known instance method for selector temp. 

我是否設置錯誤的期望?我如何設置NSMutableAttributedString的期望值?

回答

1
[[mockController expect] temp] 

告訴mockController期望應該調用方法temp。這裏的溫度只是一個變量。你真正想要的是

[[[mockController expect] andReturn:temp ] theMethodThatYouHaveTheIfStatementIn] 
相關問題