【发布时间】:2015-08-12 05:26:05
【问题描述】:
我正在编写一个测试来确认方法是否将焦点转移到下一个文本字段。我尝试了iOS unit test: How to set/update/examine firstResponder? 的代码。但它失败了。
- (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 成为第一响应者的代码。
任何建议都会有所帮助。
【问题讨论】:
-
这对我有用。你确定
self.dateCell.txtYear不是nil吗?你确定completionBlockHelper被调用了吗?尝试逐步完成测试以尝试找出发生了什么。 -
是的,很确定
self.dateCell.txtYear不是 nil 并且completionBlockHelper也会被调用。我还尝试用[self.dateCell.txtYear becomeFirstResponder]替换[self.dateCell completionBlockHelper]只是为了检查它是否有效但没有运气。 -
有什么更新吗?我遇到了同样的问题。尝试放置一个假的虚拟视图无济于事
标签: ios unit-testing xctest first-responder