我有一个 Mac 应用程序,实际上是一个 NSStatusItem,我正在尝试测试它的首选项窗口。我将此代码用作模型,因为它的工作方式与我的代码非常相似,只是我的窗口已初始化并显示在 applicationDidFinishLaunching 以外的函数中。 http://bit.ly/wH6QOk
我收到错误:未调用预期的方法:窗口
我不明白为什么会这样。这是我的测试代码:
-(void)testPreferencesInit {
mockWindowController = [OCMockObject mockForClass:[NSWindowController class]];
id mockWindow = [OCMockObject mockForClass:[NSWindow class]];
[[[mockWindowController expect] andReturn:mockWindow] window];
[[mockWindow expect] makeKeyAndOrderFront:weathervane];
[weathervane showPreferences:nil];
[mockWindowController verify];
[mockWindow verify];
id windowController;
object_getInstanceVariable(weathervane, "windowController", (void **)&windowController);
GHAssertEqualObjects(windowController, mockWindowController,
@"windowController not set on appDelegate");
GHAssertTrue([[windowController windowNibName] isEqualToString:@"Preferences"], @"Window Controller nib name not set");
object_setInstanceVariable(weathervane, "windowController", nil);
mockWindowController = nil;
}