Done Well

Notes from a Software Craftsman

Dreamforce '13

I had a great time presenting at Dreamforce ‘13. After getting home and having time to reflect on the experience I wanted to do a quick summary of my thoughts.

The Session

I was super excited to talk about unit testing iOS applications – it’s been a really fun topic to learn about the past 6 months. The general topic can be so large it’s hard to condense that down to 45 minutes, so I tried to focus it on what has had the most impact for me lately.

If I could summarize my session it would be this:

Testing doesn’t have to be an afterthought in iOS. Find the tools and frameworks that support efficiency and happiness while using the Magic Tricks of Unit Testing to write tests you will love. We also need to spread the word about testing in iOS!

Questions at the end

I got some really good feedback at the end of my session. Here are couple things we talked about:

API Drift and Mock objects.

I was asked whether or not using Mock objects can lead to situations where your unit tests pass but the application is broken. This was a great question – It’s true that using mock objects (a form of a Fake) can cause what is known as “API Drift”. API Drift is when your Fake object drifts from the contract of the object it is faking. In these cases you can have tests that seemingly pass while your application is broken.

It’s up to the developer to make sure the fake object honors the contract of the object it is faking. It turns out to be easy with Objective-C and OCMock – the compiler won’t let you stub or mock calls to selectors that don’t exist.

This is one of the great things about the compiled nature of Objective-C. With Ruby you have to usually take another step and say call_original so that if the method doesn’t exist on the real object you fail the test.

Is TDD Possible with iOS?

I was asked whether or not TDD was possible with iOS. My answer is YES! I love TDD – the demo application was created with TDD. Part of this is the tools and frameworks you use to help support TDD – I’d say the biggest one for me has been using AppCode with all of it’s powerful features for refactoring and navigation of a code base.

A great read on TDD in iOS is Graham Lee’s book on the topic. Jon Reid also has several good screencasts on TDD in context of iOS.

Slides

Video

Links

The various links from my talk: