代码测试与重构实战指南
1. 完成代码测试
在代码开发过程中,测试是确保代码质量的重要环节。我们已经完成了提交按钮动作长方法的测试,接下来要测试的是 UITextField 委托方法,该方法决定了在每个文本字段中按下回车键时会发生什么。
以下是 textFieldShouldReturn 方法的代码:
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if textField === oldPasswordTextField {
newPasswordTextField.becomeFirstResponder()
} else if textField === newPasswordTextField {
confirmPasswordTextField.becomeFirstResponder()
} else if textField === confirmPasswordTextField {
changePassword()
}
return true
}
为了确保每个文本字段的委托已正确连接,我们编写了以下测试方法:
func test_textFieldDelegates_shouldBeConnected() {
XCTAssertNotNil(sut.o
超级会员免费看
订阅专栏 解锁全文
8万+

被折叠的 条评论
为什么被折叠?



