Two common TDD mistakes are: 1) Skipping the refactoring step, and 2) Not skipping it, but refactoring only production code. So let me give you 3 reasons why it’s important to refactor tests.Continue Reading...
Can you TDD networking requests? Sure! It’s just a matter of using Dependency Injection (DI).
But first, a quick recap. Remember this design?
We want a Service class. Now when I began using this style, I made a mistake: I created a single Service class to house an entire API. This violates the Single Responsibility Principle.
The Marvel Browser may end up supporting only one API call. But I’m afraid naming it MarvelService would lead people down the wrong road. We are fetching comic book characters. So let’s use a narrower name: FetchCharactersMarvelService.
Remember: Smaller, focused classes are easier to manage than larger, godlike ones.
Let’s TDD it! Continue Reading…
Before I start the first networking calls in the TDD sample app, I have a question for you.
How would you write unit tests for this code?
NSURLSessionDataTask *dataTask = [session dataTaskWithURL:url
This fires off a request to download some data, then does something with that data. Most people would write the code pretty much this way. (Of course, supplying a URL and a completion block.)
Then they ask, “How do I unit test this?”
Think about it for a minute. What are your options?Continue Reading…
If we’ve learned the Three Steps of TDD and the Three Laws of TDD, what keeps us from doing Test Driven Development? Maybe it’s not knowing how to write unit tests. Or more specifically, not knowing how to write unit tests against “real” code.
And what keeps us from writing unit tests against our own code? I bet it’s not knowing what our many options are.
Dependency Injection can unlock your code.
A Value Object is a handy way to combine multiple values in a single object. It sounds simple — you just make each value a property, right? Well, there’s usually more to it than that. There’s even an entire objc.io article about Value Objects. …So how do you define a new Value Object?
I believe in laziness. Let’s do as little work as possible!
Objects are like horses. The less they know about their chaotic surroundings, the easier it is to control them.
We don’t want our objects to be spooked when there’s a lot going on. So let’s build ignorance into our systems.
But how? We typically write mobile apps with these things at the center:
- Communication with web services
- User interface
- Object persistence
We’re pair programming, with you driving. You’re using Xcode.
I don’t say anything because I don’t want to offend you. But you’re having to do So. Much. Typing.
They say typing isn’t the slowest part of programming. But as I sit with you, I wonder… Why isn’t the code automatically appearing? We’re on a computer working in a computer language, so why doesn’t the IDE understand your intent? Why do you have to make the same changes in so many places?
Oh yeah. You’re using Xcode. Continue Reading…
With the imminent release of iOS 9 and the usual fast adoption rate, many developers can finally start using APIs introduced in iOS 8. One of these is UIAlertController, which unifies code for alerts, action sheets, and iPad popovers.
So… can we write unit tests against a UIAlertController? Let’s learn some tricks for dealing with Cocoa Touch. Continue Reading…
iPhreaks is a terrific podcast done as a panel discussion. The panel often brings strong experience from other platforms. (In fact, iPhreaks is the iOS cousin to the Ruby Rogues panel.) They already discussed TDD in episode 95. Following up on that, I’m honored that they invited me as their guest to talk more about TDD and Testing in episode 116.