pivotal-legacy / PivotalCoreKit

Shared library and test code for iOS and macOS projects
http://pivotallabs.com
Other
168 stars 85 forks source link

PCK stub for modal presentation doesn't really respect all these lifecycle calls #163

Closed richball closed 8 years ago

richball commented 8 years ago

While writing a test in Cedar I'm trying to validate specific behavior in viewWillDisappear -- The context is simply that my subject view controller presents another view controller modally after tapping a UIButton and executes important logic in viewWillDisappear.

After rendering the view in test, and invoking the tap method from UIControl+Spec.h on the UIButton, the viewWillDisappear method is never called on my subject.

Any insights or a suggestion on how to test what occurs in viewWillDisappear?

akitchen commented 8 years ago

If you're doing headless testing, the will/did appear/disappear methods will never be called as the views aren't actually being displayed. In order to exercise code in those methods naturally, you will need to do integration-style testing and allow your controllers' views to be drawn.

Otherwise, in headless unit tests one needs to either call the will/did appear/disappear methods manually, or consider using beginAppearanceTransition:animated: / endAppearanceTransition instead.

On Mon, Oct 5, 2015 at 2:33 PM, Rich Ball notifications@github.com wrote:

While writing a test in Cedar I'm trying to validate specific behavior in viewWillDisappear -- The context is simply that my subject view controller presents another view controller modally after tapping a UIButton and executes important logic in viewWillDisappear.

After rendering the view in test, and invoking the tap method from UIControl+Spec.h on the UIButton, the viewWillDisappear method is never called on my subject.

Any insights or a suggestion on how to test what occurs in viewWillDisappear?

— Reply to this email directly or view it on GitHub.

Andrew Kitchen Associate Director, Engineering

Pivotal Labs 875 Howard St., Fl 5 San Francisco, CA 94103 mobile +1.415.501.0085

tjarratt commented 8 years ago

Was Andrew's response helpful @richball?

It's unfortunate, but all of the UIViewController lifecycle methods are called asynchronously by the runtime, and there's not often a good place for Cedar / PCK to assume we should call it. This affords users the flexibility to call it when it makes sense for their tests.

You may also find this article about testing UIViewController life cycle events with Cedar to be of interest:

http://blog.otaviocc.com/blog/2014/02/16/cedars-subjectaction

Please re-open this issue if you have more questions. I'd love to answer them!