我需要编写一个单元测试来检查按下按钮是否会导致适当IBAction
的调用。
这是我的测试方法:
- (void)testWhether_loginBtnTapped_IsCalledAfterUserTapLoginButton
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
GoingToLoginViewController *myViewController = [storyboard instantiateViewControllerWithIdentifier:@"GoingToLoginVC"];
id vcMock = [OCMockObject partialMockForObject:myViewController];
[[vcMock expect] loginBtnTapped:[OCMArg any]];
[myViewController.loginBtn sendActionsForControlEvents:UIControlEventTouchUpInside];
[vcMock verify];
}
当我运行测试时,我有日志消息:
error: testWhether_loginBtnTapped_IsCalledAfterUserTapLoginButton (Ticket2Tests) failed: OCPartialMockObject[GoingToLoginViewController]: expected method was not invoked: loginBtnTapped:<OCMAnyConstraint: 0xfd3aeb0>
当我在模拟器上运行我的应用程序时,按钮可以正常工作- (IBAction)loginBtnTapped:(id)sender;
并被调用。
我做错了什么,我应该怎么做才能使测试通过?