Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Start Doing TDD in iOS

DZone's Guide to

How to Start Doing TDD in iOS

Test Driven Development (TDD) is an essential technique to know. And it's something you can confidently do when developing for iOS.

· Mobile Zone
Free Resource

Get gorgeous, multi-touch charts for your iOS application with just a few lines of code.

I like to do apps. As a newbie TDD developer, I've made my apps with tests but not driven by tests. I want to change that. I'm learning to be a Craftsman, so TDD is an essential technique to know. It's your main tool. At Codurance it's unthinkable that you could code without doing TDD. That's one of the things that you learn in our apprenticeship program: to be able to do TDD without thinking about it and feel as if it's natural: as you breath to survive you do TDD to code.

So today I feel pretty much confident that I'm able to do TDD (at least in C#), and so I've come back to my apps and I've decided to change them to apply all the good practices that I've learned in my first month at Codurance.

Oh God! What have I done! It's amazing how you go back now, look at your code and think: What that hell was I doing? How could I write such code? I really just wanted to delete everything and start again... Well, we all know that that is not really possible when you have an app published and selling and you have users that send you requests for new features...

So what could I do? I thought it would be a good idea to refactor all my code, and at least make it a little bit cleaner, with unit tests everywhere rather than just in the main features (Oh God! I know!!!! It's horrible...) All the horrible things that they say to you that you will find in the real world when you finish the apprenticeship have come true when looking to at own code, so frustating!!!! So to be proficient in doing refactoring in iOS, I must be able to do TDD correctly, this means not even thinking about it when I code in Objective-C. That was not the stage that I was at... So, what can I do?

I decided to start were I started at Codurance: to do katas, one after another, get the logic of the language, solve small problems first, and then go to bigger katas where you can apply your OOP knowledge. I've googled for katas in Objective-C and I've got a lot of links: I was thrilled! iOS developers are sharing their katas. Then I followed the links... Most of then send me to a "This webpage is not available" page. Even the Objective-C version of String calculator by Roy Osherove is going to the same page... And then I found a screencast that is using iOS 5.5? We are already in beta for 9!!!

Well I can just conclude that iOS developers don't share their code! So let's change that. Since we talked about the String Calculator, let's start with this kata and see what we can do with it. I'll do the beginner version. Here's my attempt, found at Github.

This article was first published on the Codurance blog.

.Net developers: use Highcharts, the industry's leading interactive charting library, without writing a single line of JavaScript.

Topics:
mobile ,tdd ,ios

Published at DZone with permission of Ana Nogal, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}