Unit testing your UIViewController been pushed properly

I had lots of UIViewController they ends up by pushing another UIViewController. That's say I had a AUIViewController it would push BUIViewController by MyUINavigationController.

When writing unit tests we test AUIViewController independently, in average cases self.navigationController will be nil.

We need a mock UINavigationController injected.

AssociatedObject did the trick.

Don't forget #import <objc/runtime.h>

My matcher is OCHamcrest, mocking library is OCMockito and Unit test framework is build-in XCTest.

Category encapsulated open source on GitHub

comments powered by Disqus