Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unit-test IBOutlet connections?

I've been trying to verify in my tests (GTM) that when a nib file is loaded, its IBOutlets were properly connected in InterfaceBuilder.

However I keep getting nil references, despite calling [myViewController viewDidLoad] before asserting that the reference should exist.

Are there any gotchas here, or should this be mocked somehow ?

cheers

like image 527
julien Avatar asked Aug 12 '10 12:08

julien


2 Answers

calling [myViewContoller viewDidLoad] does not load the view. You want [myViewController loadView], which loads up the .nib and the references.

like image 184
NebulaFox Avatar answered Nov 20 '22 11:11

NebulaFox


You shouldn't be calling -viewDidLoad.

If by "when a nib file is loaded", you mean you're calling -initWithNibName:bundle:, that does not load the nib. That just sets the nib name that is used to load the view. The "correct" way to load the view is to call -[UIViewController view] (which calls loadView if it was not already loaded, which by default loads from the nib, which has a default name of [[self class] description] or so, I think). -[UIViewController view] will call viewDidLoad for you.

like image 43
tc. Avatar answered Nov 20 '22 12:11

tc.