views:

16

answers:

0

I'm writing unit tests. And I cannot test one function, because it calls keyWindow

UIWindow* window = [UIApplication sharedApplication].keyWindow;

And keyWindow returns nil (I don't have any window). But I need to return anything, but nil.

I used category to manually set keyWindow value, but this didn't work

@interface UIApplication(UnitTest)
- (id)getKeyWindow;
@end

@implementation UIApplication(UnitTest)
- (id)getKeyWindow
{
    return [self keyWindow];
}
@end

// compiler error: lvalue required as left operand of assignment
[[UIApplication sharedApplication] getKeyWindow] = [[UIWindow alloc] init]; 

What would you do in my place?