Test Input Focus

We have one more delegate method, textFieldShouldReturn(_:). It does two things:

  • When the user presses the return key in the username field, the input focus should move to the password field.

  • When the user presses the return key in the password field, the keyboard should be dismissed, and the login process should start.

Let’s start with the second behavior (logging in) before moving to the challenge of testing keyboard input focus. Add a test that populates the text fields, and confirms that pressing the return key in the password field starts the login process. As we did in Test Delegate Methods, we’ll ask the text field for its delegate and talk to it:

 func​ ​test_shouldReturn_withPassword_shouldPerformLogin ...

Get iOS Unit Testing by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.