I'm looking for a "best practice" / "low test friction" way to do state based testing on view controllers inside my base AppDelegate class. Currently the below provides an easy way to stub in my own UIViewController (using ocmock) when something happens to it inside a method on the class.
-(FirstViewController *)getFirstViewController
{
if (self.viewController1)
{ return self.viewController1; }
self.viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
return self.viewController1;
}
The first question I have -Is this a valid way to stub out / inject my own mock view controller for testing? (seems to work great but I'm not sure if this is how the pros are doing state based testing today)
The next question I have -Is it valid to keep 1 copy of the view controller in memory like this (only creating it from scratch once for the life of the app) ?
**note- I would dependency inject this but my init is already large enough just injecting the nav controller and tab bar controller so that's not an option for this large class sadly