Viewing Controllers --iPhone

My question is 2 times. 1. Can I use OCUnit to test View controllers. If so, how do I do this? If not, is there another test kit that I can use?

+3
source share
1 answer

You definitely can. Say you had a UITableViewController, and you wanted to make sure it had 2 sections of 5 rows; this is easy to do in a testing method, for example:

- (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 using OCMock to help you test your controllers. You can easily make fun of the view and make sure your controller interacts with it properly.

+5

Source: https://habr.com/ru/post/1716635/


All Articles