iOS单元测试:如何对firstResponderStatus进行单元测试
我正在编写一个测试,以确认是否有方法将焦点转移到下一个文本字段。我试过了你的密码。但它失败了iOS单元测试:如何对firstResponderStatus进行单元测试,ios,unit-testing,xctest,first-responder,Ios,Unit Testing,Xctest,First Responder,我正在编写一个测试,以确认是否有方法将焦点转移到下一个文本字段。我试过了你的密码。但它失败了 - (void)testFocusMovedToYearField { UIWindow *window = [[UIWindow alloc] init]; [window addSubview:self.dateCell.txtDay]; [window addSubview:self.dateCell.txtYear]; [self.dateCell completionBl
- (void)testFocusMovedToYearField {
UIWindow *window = [[UIWindow alloc] init];
[window addSubview:self.dateCell.txtDay];
[window addSubview:self.dateCell.txtYear];
[self.dateCell completionBlockHelper];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:5.0]];
XCTAssertTrue([self.kioskDateCell.txtYear isFirstResponder]);
}
函数completionBlockHelper
包含使txtYear
成为第一响应者的代码
任何建议都会有帮助。该窗口需要成为关键窗口。在Swift:
窗口中。makeKeyAndVisible()
这对我很有用。您确定self.dateCell.txtYear
不是nil
?您确定正在调用completionBlockHelper
?尝试单步执行测试,以尝试了解发生了什么。是的,非常确定self.dateCell.txtYear
不是nil,并且也会调用completionBlockHelper
。我还尝试将[self.dateCell completionBlockHelper]
替换为[self.dateCell.txtYear becomeFirstResponder]
,只是为了检查这是否有效,但运气不佳。有更新吗?我也遇到同样的问题。试图在虚拟视图中设置一个虚拟视图,但没有效果