title: How can I write an automated unit test of a GUI in Xcode?
body: <p>I want to write a unit test of just the GUI part of my Cocoa application.</p>
  
  <p>In the textbook unit test, there's a test framework and test case that calls the unit under test. All the code below that unit is mocked out. So, both the input and the output are controlled and monitored; only the code in the unit under test is tested.</p>
  
  <p>I want to do the same thing where the unit under test is my GUI:<br>
  1) Set up some kind of framework where I can write code that will manipulate and inspect GUI controls.<br>
  2) Connect my GUI controls to mocks of my actual code, not to the real instances.<br>
  3) Run the test, which manipulates the controls and then checks the mock object to see whether the correct methods were called with the correct parameters and checks the GUI to see whether the responses from the mock object causes the correct changes in the widgets.</p>
  
  <p>Anyone doing this? If so, how? Any ideas on how I could do this?</p>
  
  <p>Thanks,</p>
  
  <p>Pat</p>
  
  <p>(Edit) To give a very specific example, I want to:<br>
  1) Write a test case that will select the menu item 'MyMenu' -> 'MyItem'. In this test case, I want to check to see that the method [AppDelegate doMyItem] gets called precisely once and that no other methods in AppDelegate get called.<br>
  2) Generate a mock object of AppDelegate. (I know how to do this)<br>
  3) Somehow (handwaving here) link my application so that a mock instance of AppDelegate is linked in instead of the real one.<br>
  4) Run the test. Watch it fail because 1) I haven't created MyMenu yet. 2) I haven't created MyItem yet. 3) I haven't done the IB work to connect MyItem to [AppDelegate doMyItem], or 4) because I haven't written the 'doMyItem' method yet.<br>
  5) Fix the above four issues (one at a time if I'm feeling really pedantic that day).<br>
  6) Run the test again and watch it succeed.</p>
  
  <p>Does this make the question clear?</p>