Most Popular in Apple
-
A fix for those "Pairing Record Missing" errors
-
Blog sale!
-
You're the Pundit: Does a 7" iPad make sense for the education market?
-
Anonymous Hacks Syrian President?s Email. The Password: 12345
-
Backdoor in TRENDnet IP Cameras Provide Real-Time Peeping Tom Paradise?
-
Adobe confirms: no Flash for Chrome on Android
-
Twelve South HoverBar a unique way to marry iPad and iMac
-
White MacBook reaches end of life, education sales to cease
-
The Most Prolific Hacker on the Internet: A One-Handed Shadow
-
O2 network issues hinder iPhone users
iPhone devsugar: Unit testing for iPhone view controllers
Filed under: Apple
Unit testing refers to a software validation methodology that allows programmers to test individual program units for correctness. It's been an ongoing question in the iPhone developer community as to whether the iPhone's view controller class is testable or not.In response to these discussions, iPhone developer Jonah Williams has written up a view controller unit testing how-to over at the Carbon Five web blog. His write-up offers examples that show how to incorporate some best practices into your code.
Williams points out how broken NIB bindings are a common problem for iPhone OS applications. To address these issues, he regularly adds simple assertions that test that each IB outlet and action are set properly from inside his view controller class implementations. These assertions check that IBOutlet instance variables are not set to nil and that IBAction targets have been assigned, adding a layer of protection against broken bindings.
Another typical view controller issue involves responding to application memory warnings. To respond, he adds tests that ensure that each view-dependent property gets correctly released and re-created as views unload and then later reload. By building these into test methods, he can execute this behavior on demand, and ensure that the sequence will execute flawlessly in real world conditions.
Finally, Williams discusses view controller interdependencies. Often instances are tightly intertwined, with objects acting as clients for each other. For example, a simple table view controller, living within a navigation controller, might present a detail view via yet another view controller when a row is selected. That's three separate controllers to account for, when you really only want to test one at a time. Williams suggests isolating these view controllers away from their interdependencies to test each component separately and provides examples of how you can do so.
What made Williams' approach pop for me is how he carefully exposes and isolates dependencies for testing. These are features that can otherwise be hard to inspect and validate in the normal course of programming. His write-up is well worth reading through, and provides an excellent jumping off point for investigating view controller unit testing.
TUAWiPhone devsugar: Unit testing for iPhone view controllers originally appeared on The Unofficial Apple Weblog (TUAW) on Wed, 10 Mar 2010 16:30:00 EST. Please see our terms for use of feeds.
More Stories in TUAW
- App usage doesn't drop during Super Bowl -- except during halftime
- Daily iPad App: Tweetbot emerges as a top Twitter client for the iPad
- You're the Pundit: Does a 7" iPad make sense for the education market?
- White MacBook reaches end of life, education sales to cease
- Apple resellers in Europe say inventory delays affecting business
- Siri may speak and understand Chinese, Japanese, and Russian by March
- TUAW TV Live: Looking at what's new in the Appleverse
- Apple stock gains nearly $100 since Steve's passing
- Daily Update for February 8, 2012
- Protests against iPhone factory conditions planned at Apple Stores
Most Popular Stories
A fix for those "Pairing Record Missing" errors
Blog sale!
You're the Pundit: Does a 7" iPad make sense for the education market?
Anonymous Hacks Syrian President?s Email. The Password: 12345
HMC Commands
Backdoor in TRENDnet IP Cameras Provide Real-Time Peeping Tom Paradise?
Server error: 501 #5.1.3 in UNIX
Adobe confirms: no Flash for Chrome on Android
Replace pipe with Broken Pipe
Twelve South HoverBar a unique way to marry iPad and iMac