I am trying to write some application tests for my app based on the iPhoneUnitTests examples on Apple dev site. Particularly I am having trouble “tapping” through elements in the app, that is, simulating the tap calling methods that make view controllers appear o disappear.
For instance I have this test:
- (void)testAddMeal
{
HomeScreenController *hsCtrl = (HomeScreenController*)mainViewController;
[hsCtrl tableView:hsCtrl.tblView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
nutritionStrategyController = (NutritionStrategyController*)((UINavigationController*)mainViewController.modalViewController).topViewController;
[nutritionStrategyController tableView:nutritionStrategyController.tblView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
}
Which opens a first UIViewController selecting a table cell and then a second UIViewController should appear selecting a table cell in the new UIViewController.
Problem is, the test fails with this error:
Unknown.m:0: error: -[NutritionStrategyTests testAddMeal] : Attempting to begin a modal transition from <UINavigationController: 0x113a2fc0> to <NewMealTrackingController: 0x9353090> while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed
So my question is, how do I create a test for this?
Unit tests are for testing the behavior of specific bits of code, classes, modules etc. If you want to automate user input, it is a different kind of test, you can look into the UIAutomation instrument, which is dedicated to this type of testing.