Jump to ratings and reviews
Rate this book

Test-Driven iOS Development

Rate this book
As iOS apps become increasingly complex and business-critical, iOS developers must ensure consistently superior code quality. This means adopting best practices for creating and testing iOS apps. Test-Driven Development (TDD) is one of the most powerful of these best practices. Test-Driven iOS Development is the first book 100% focused on helping you successfully implement TDD and unit testing in an iOS environment. Long-time iOS/Mac developer Graham Lee helps you rapidly integrate TDD into your existing processes using Apple's Xcode 4 and the OCUnit unit testing framework. He guides you through constructing an entire Objective-C iOS app in a test-driven manner, from initial specification to functional product. Lee also introduces powerful patterns for applying TDD in iOS development, and previews powerful automated testing capabilities that will soon arrive on the iOS platform. Coverage includes Understanding the purpose, benefits, and costs of unit testing in iOS environments Mastering the principles of TDD, and applying them in areas from app design to refactoring Writing usable, readable, and repeatable iOS unit tests Using OCUnit to set up your Xcode project for TDD Using domain analysis to identify the classes and interactions your app needs, and designing it accordingly Considering third-party tools for iOS unit testing Building networking code in a test-driven manner Automating testing of view controller code that interacts with users Designing to interfaces, not implementations Testing concurrent code that typically runs in the background Applying TDD to existing apps Preparing for Behavior Driven Development (BDD) The only iOS-specific guide to TDD and unit testing, Test-Driven iOS Development covers both essential
concepts and practical implementation.

256 pages, Paperback

First published April 1, 2012

Loading interface...
Loading interface...

About the author

Graham Lee

23 books2 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
15 (14%)
4 stars
43 (42%)
3 stars
27 (26%)
2 stars
16 (15%)
1 star
1 (<1%)
Displaying 1 - 10 of 10 reviews
Profile Image for Romans Karpelcevs.
179 reviews47 followers
August 14, 2017
Staring out as a great book, it quickly deteriorated into a mess of mocks and contradictions.

I'll be frank with my expectations: I don't see a point in general example TDD and testing books when there are great books by Uncle Bob and Kent Beck and other grands. What makes sense and adds value is how to get around platform difficulties or common problems of a particular domain. And this book starts as a good general example for the easy things (data types, entities, parsing) and becomes clumsy and ridiculous when getting into the woods of iOS development which usually cause problems: view controllers, table views and networking.

So the good parts is solid model implementation using TDD, separating concerns, gradually moving design with the requirements. Core TDD points of R/G/R and only doing as much as needed are respected. Detailed and thorough way of explaining helps any novice. App also has a nice pattern of sending `NSNotificationCenter` events to tell other parts of the app to react, and there are a few good points on view testing and such. Book also uses outdated testing and networking code, as well as soon-to-be outdated language, but it isn't a problem at all if you're willing to look for solutions and ideas rather than instructions. But then there's also the bad.

It all starts with author exposing a private variable through a test-only subclass with a getter, and goes downhill. Instead of solving design issues through interfaces or otherwise, it relies on ObjC not asking for casting for `id` and replaces UIKit objects with fake ones which simply answer to (some of) the same methods. Then it goes on to add test-only categories for objects relying on their internal implementation, and, not stopping there, starts swizzling methods to assist with UITableView testing. It also calls UIKit lifecycle methods directly and does other minor sins, like growing design from idea of a future implementation rather than requirements at hand.

Not surprisingly, bad test code leads to bad design. Supposedly decoupled view controller eventually has a switch-case for all screens in the app. Whenever author exposes a private implementation details a refactoring is screaming to change implementation. Both networking and table view delegate use unscalable design patterns. It just doesn't work with any larger app, separating table view's delegates and data sources from view controller or putting all fetching logic into one communicator. The hints were right there in the complexity of the test code (which often was longer than the implementation code) but weren't addressed.
Profile Image for Ettore Pasquini.
135 reviews111 followers
May 9, 2013
Pretty good introduction to TDD on iOS. Throughout the book an entire app (a basic StackOverflow browser) is built from scratch using TDD, covering all its functional requirements. This included model and controller code. A long time is spent discussing UITableView and its data sources and delegates, which makes sense since they are such an important piece of UIKit. The author stops at the view level, so things like testing the positioning of UI elements in relation to others is not discussed.

I really appreciated the rigor with which TDD is employed here: the author is pretty relentless in the red-green-refactor mantra, designing mocks etc, although sometimes, especially while following the various table views callbacks, the testing code gets intricate and it's not exactly obvious how to write those in-depth controller tests.

The main drawback of this book is that it focuses on the testing framework bundled with Xcode, OCunit. OCunit does its job and it's well integrated, but I don't think it's the best testing solution available nowadays. Perhaps something more than a half page could have been spent on BDD; and perhaps a discussion about additions like OCMock or an analysis of other established testing frameworks could have been useful.

The biggest plus is that after reading this you want to do TDD! Yes you're going to have to invest some time on it to get used to it, but I liked how the author stressed that the payoff on overall quality (OO design, stability, maintainability) is gonna be big.
Profile Image for Mohannad Hassan.
162 reviews54 followers
August 14, 2017

Having already tried TDD and gone through few months applying it gradually to an existent app, I started reading this book with the attempt of finding the best material on TDD first, and a chance to validate some ideas that I had in the process. This book has served these two goals to a good extent.

First of all, it's a good step-by-step guide. It demonstrates building a relatively small app from the grounds up with TDD in mind. The app is simple and looks like the average app one usually encounters.

The real merit of this book is the explanation of the real effect unit testing in general and TDD specifically have on the development process. For me, unit testing concluded many thoughts I had on the proper OOP architecture of any piece of software. Following specific architecture guidelines for the sake of testability should not sound like a good plan after reading this book. Yet, this hides the bigger picture; the fact that the all components of the system are clearly defined, explained well by their interfaces, and laid out within the larger map of the system.

I guess we can easily find a correlation between the quality of a software's architecture and its testability.

The first chapter had this very suitable and fitting quote

If testing is something we do to support our software projects, it must support the goal of making a profit. … If you can’t demonstrate that value, the customers may not buy the product.

One may lose the needed amount of pragmatism while seeking perfection in his profession.
Profile Image for pluton.
277 reviews8 followers
May 21, 2015
It's a pretty interesting and, I believe, actually one of the kind – TDD on iOS – book. It explains and show how you can build different app layers using TDD. The book is quite old already, but you still can build the sample application adapting and fixing things on the fly. Sometimes, it uses weird ways (as for me) to test functionality; and the sample code uses manually built mocks, which is tiresome, instead of using a mocking framework, but it makes you understand how they actually work. A couple of chapters at the end summarize some design patterns that you can use to build testable systems.
The book inspired me to try TDD for a new functionality of a project and I should say I like this approach and can see its big benefits. Read this book, check some articles online, and try it!
Profile Image for Sascha.
13 reviews1 follower
February 15, 2015
A lot of the book is one example. This could help if you're completely new to unit testing but familiar with iOS development.
The chapters after the example are actually about interesting topics like testable architecture or adding tests to an existing codebase, but they are not deep enough anymore.
So I recommend reading more specialized books. These are usually for a different programming language, but the knowledge is easy to port.
Some are also referenced in the book, like Working Effectively with Legacy Code by Michael Feathers.

Profile Image for Malcolm Bastien.
23 reviews4 followers
February 24, 2013
Everything started out great with this book, but then at one point it shifted gears and started doing tests on mock objects and I was completely lost for the rest of it.

It was super frustrating to read a book on test-driven development then all of a sudden be stuck and confused.
Profile Image for Brian.
26 reviews
February 12, 2013
Ambitious book, but way too "do-it yourself" to be practical. The majority of the book seems to be devoted to building mocks or stubbing methods--solved problems if you use Kiwi or OCMock. I wanted to enjoy it, but it just wasn't for me I guess.
Profile Image for Greg.
78 reviews
February 25, 2013
Felt to me more like a worked example of TDD for iOS than an explanation of how to add unit testing to your repertoire. It works well as supplementary material if you're familiar with unit testing and are starting out in iOS development. Not recommended as a first "how to unit test" book.
Displaying 1 - 10 of 10 reviews

Can't find what you're looking for?

Get help and learn more about the design.