简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM