title: iOS unit test: How to set/update/examine firstResponder?
body: <p>How do you write first responder unit tests?</p>
  
  <p>I'm trying to write a test to confirm that a method advances focus to the next text field. <code>controller</code> is a descendant of <code>UIViewController</code>. But this exploratory test fails:</p>
  
  <pre><code>- (void)testFirstResponder
  {
      [controller view];
      [[controller firstTextField] becomeFirstResponder];
  
      STAssertTrue([[controller firstTextField] isFirstResponder], nil);
  }
  </code></pre>
  
  <p>The first line causes the view to be loaded so that its outlets are in place. The text fields are non-nil. But the test never passes.</p>
  
  <p>I'm guessing that <code>becomeFirstResponder</code> doesn't set the first responder right away, but schedules it for later. So is there a good way to write a unit test against it?</p>
  
  <p><strong>Pulling up answer from comment in accepted answer…</strong> Let things run for a short time:</p>
  
  <pre><code>[[NSRunLoop currentRunLoop] runUntilDate:[NSDate date]];
  </code></pre>
  
  <p>I've also found I need to create a UIWindow and drop the view controller's view into it, as stated in the most-upvoted answer.</p>