nib files and outlets in cedar tests

10 views
Skip to first unread message

Jay

unread,
Apr 28, 2015, 4:34:37 PM4/28/15
to cedar-...@googlegroups.com
I'm getting a lot of failed tests with classes where I use a .xib and autolayout,  they seem to be related to views not loading on time, as most of them are due to nil views.

I have a specific test where I check that an imageView isn't nil, this imageView is in my nib and has an outlet in my class..  My app is running fine and it can access the views fine, but these tests seem to randomly fail. 

Do I need to do something special to work with nib files/autolayout?

Andrew Kitchen

unread,
Apr 28, 2015, 5:11:28 PM4/28/15
to cedar-...@googlegroups.com
Hi Jay,

There are some subtleties here depending on how you are testing.  I'm assuming you're doing more unit-style tests and not integration tests in an actual key and visible window.

Assuming your test subject is a UIViewController, it is worth noting that its view is loaded lazily.  Many developers assert that the view is not nil in order to force its loading, e.g. subject.view should_not be_nil;

If you also want autolayout to lay out your views, you probably want to perform [subject.view layoutIfNeeded]; -- this will invoke the lazy loading as well as request auto layout.  you also may want to perform beginAppearanceTransition.../endAppearanceTransition or call viewWill/DidAppear: if not doing integration-style testing.

Hopefully this helps.  if not, let us know with more concrete examples and we'll try to help.

Thanks!
Andrew

--
You received this message because you are subscribed to the Google Groups "Cedar Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cedar-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jme...@gmail.com

unread,
Apr 29, 2015, 8:59:15 AM4/29/15
to cedar-...@googlegroups.com
This helps and explains the behaviors I noticed - I was having issues with views being nil, but when I would log them, my tests would never fail.. Makes sense now!

Thanks!
Reply all
Reply to author
Forward
0 new messages