It’s one thing to say, “Do test-driven development.” But practicing TDD requires a set of tricks—you need techniques to enable test-driven development in your particular environment. It’s these techniques which I hope to pass on to you through a case study of building an iOS TDD sample app.

Treasure Chest by Tom Garnett, used under CC BY 2.0
I’ve accumulated a treasure chest of TDD ideas over the years. These ideas are often not my own, but are other people’s ideas which I collect and curate. Some are about object-oriented design. Some are about working in Xcode and Objective-C. And some are particular to iOS development. I’ve collected many, and continue to gather new ones.
I’m building this TDD sample app so that you and I can browse through this treasure chest together. You may have tried test-driven development and given up on it. Or maybe you’re still trying, but finding it frustratingly slow. The ideas we will explore together will help you break through to make headway in your TDD journey, so that you can experience the freedom and ease that comes from automated testing and clear code.
[This post is part of the series TDD Sample App: The Complete Collection …So Far]
TDD Sample App: Marvel Browser!
A worked example can’t be hand-wavy; it needs to be something concrete. I asked you for concrete ideas, and some of you suggested the Marvel Comics API. It looks clear and straightforward, so it should work well for our TDD sample app. Besides, the dataset will be fun!
The Marvel Comics API provides a way to look up comic book characters, so that’ll be the main focus of the app. But let’s break that down further. Here are a few use cases that come from the way we use mobile apps:
- User initiates search for Marvel characters, where the names of those characters match some given prefix. The results include character images and other information.
- User requests next page of results.
- User implicitly cancels current request by navigating away.
This small set of use cases is common to most networking apps. It’ll give us plenty to start with.
20 Possible Topics (TDD and Otherwise)
Although we have only three use cases, working through them will lead us through many topics, such as:
- Project setup
- Managing app start-up
- Test organization
- Asynchronous networking
- Building requests
- Building objects from JSON responses
- Error handling
- Logging
- Canceling requests
- Clear architecture
- SOLID code
- Paged results
- View controllers
- Dependency injection
- Storyboards
- Collection views
- Displaying images
- Stronger static analysis
- Coupling, cohesion, and complexity
- Managing the class dependency graph
Despite the numbering, this isn’t an ordered list. Some of the topics are about applying TDD, while others are about design issues. What “test-driven development” drives isn’t just code with tests. TDD also drives design. So even though I’m calling this a “TDD sample app,” design issues will weave in & out of the examples.
What “test-driven development” drives isn’t just code with tests. TDD also drives design.
I may sometimes write something that looks like a digression. As I see it, anything that can help you work more efficiently is fair game. That’s why I wrote 6 Simple Power Tools for Better Git Use; it’s the first set of ideas that came up as I started the Marvel Browser project. But in general, expect a steady flow of TDD examples and related object-oriented design issues.
Subscribe to Follow / Pass Along to a Friend
So get ready! Some ideas will be new to you, and you’ll be able use them immediately. Some techniques may raise questions. When that happens, please raise those questions, because with good discussions, we all win.
To make sure you don’t miss a single post in this series, please subscribe. You’ll receive new posts directly by email. Or if you have already subscribed, can you think of a friend or colleague who would benefit from this series? Then be sure to pass this article along to them.
Question: Which topics do you look forward to the most? You can leave a comment by clicking here.
[This post is part of the series TDD Sample App: The Complete Collection …So Far]
Looking good.
I need some design knowledge so I am looking forward to those discussions.
Very nice program, looks to real apps we used to develop in my company, I’m impatient to read all this.
These are the topics I look forward to the most:
Test organization
Asynchronous networking
Building requests
Error handling
Logging
Canceling requests
Clean architecture
SOLID code
Paged results
Coupling, cohesion, and complexity
Managing the class dependency graph
Hello Jon,
I’d be really interesting on how you use storyboards with builders and dependency injection (if possible).
I was yesterday discussing with @codermay about how to move our builder approach to storyboard, and I don’t think it’s possible.
Also it will be very interesting to know how you choose between two technologies or approaches when the gains/loses are no quantifiable and clear (sometimes is just about feeling or preference than engineering? ).
Thanks!
These are the topics I look forward to the most:
Error Handling
Clean architecture
SOLID code
Can’t wait to see the real code. Avengers, gear up!
These are the topics I look forward to most:
Error handling
Clean architecture
Dependency injection
Coupling, cohesion, and complexity
Managing the class dependency graph
very good initiative! I’m really looking forward to.. thanks!
Really nice!! Thank you for doing this, it’s sure will help many of us.
If possible, please cover also one of the libs or way to map REST service directly to Core Data (saving & fetching, updating etc) and also unit testing (TDD) on database.
Hey Jon, I cannot find where you may have posted this case study. Very interested. Thanks!
Richard, the code is still in its infancy, but you can follow the commits at https://github.com/jonreid/MarvelBrowser