views:

105

answers:

1

My question is 2-fold. 1. Can I use OCUnit to test View Controllers. If so, how should I do it? If not, is there another Testing Kit I can use?

+1  A: 

You definitely can. Say you had a UITableViewController, and you wanted to make sure that it had 2 sections with 5 rows each; that is easily done in a test method like so:

- (void) testTableHasCorrectRowsAndSections
{
  id tableViewController = [[[YourTableViewControllerSubclass alloc] init] autorelease];

  STAssertEquals(2,[tableViewController numberOfSectionsInTableView:nil],@"");
  STAssertEquals(5,[tableViewController tableView:nil numberOfRowsInSection:0],@"");
  STAssertEquals(5,[tableViewController tableView:nil numberOfRowsInSection:1],@"");
}

I would also recommend also utilizing OCMock to help you with testing your controllers. you can easily mock a view and ensure that your controller is interacting with it properly.

Kevlar