我在http://pathfindersoftware.com/2009/01/testing-delegate-ocmock/之后开始使用OSX TDD和OCMock。
现在,我正处于启动时我的应用程序显示登录的阶段,并希望测试具有无效/无凭据的用户无法登录。
详细说明,AppDelegate将自己设置为登录视图控制器的委托,尝试登录(不设置凭据),然后调用委托方法didNotAuthorizeUser
。但是我在测试中遇到错误。更多详情如下。
SomeDelegateProtocol
)id mocklvc = [OCMockObject mockForClass:[LoginViewController class]];
[appDelegate setLoginViewController:mocklvc];
id qtApp = [OCMockObject mockForClass:[NSApplication class]];
id loginDelegate = [OCMockObject mockForProtocol:@protocol(SomeDelegate)];
[[mocklvc expect] setLoginDelegate:loginDelegate];
[[mocklvc expect] authenticateWithService];
[[loginDelegate expect] didNotAuthorizeUser];
//This row returns NSInternalConsistencyException
//OCMockObject[LoginViewController]
//unexpected method invoked setLoginDelegate:<AppDelegate>
[appDelegate applicationDidFinishLaunching:qtApp];
[mocklvc verify];
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[self.loginViewController setLoginDelegate:self];
}
@property(weak)id&lt; SomeDelegate&gt; loginDelegate;
调用应用程序didFinishLaunchingWithOptions时:我在测试中收到以下错误,
NSInternalConsistencyException OCMockObject[LoginViewController] unexpected method invoked setLoginDelegate:<AppDelegate>
你认为这首先是一个好的设置吗?关于如何重写测试或实际解决错误的任何想法?
答案 0 :(得分:0)
loginDelegate
的{{1}}解决了这个问题。