I want to test my app delegate make window as key window after launch. So I write the following tests.
- (void)setUp
{
window = [[UIWindow alloc] init];
appDelegate = [[FGAppDelegate alloc] init];
appDelegate.window = window;
appDidFinishLaunchingReturn = [appDelegate application: nil didFinishLaunchingWithOptions:nil];
}
- (void)tearDown
{
window = nil;
appDelegate = nil;
}
- (void)testWindowIsKeyAfterApplicationLaunch
{
STAssertTrue(window.keyWindow, @"App delegate's window should be key.");
}
In my app delegate the method applicaton:didFinishLaunchingWithOptions:
...
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
The test failed and told me window.keyWindow should be true. Is there anything wrong? How can I fix the test?