TDD is a series of small steps. It can be difficult to grasp until you see those steps demonstrated. That’s why I made this screencast. It was sparked by a Stack Overflow question that said, “All the examples of unit testing I read about seem to be extremely simple and trivial.” The question asks how to write unit tests for a piece of sample code. What’s interesting about this problem is that it uses NSUserDefaults.
- What to do with an external object (in this case, the NSUserDefaults singleton). Dependency injection to the rescue!
- My basic setup: OCUnit + OCHamcrest + OCMockito (along with my test case template and test code snippets)
- The 3 steps of “The TDD Waltz”
- We TDD our way to the desired functionality
- The Stack Overflow question. My original answer illustrates setter injection, as opposed to the (better) constructor injection of the video.
- My Resources page, where you can get OCHamcrest, OCMockito, and my test case template
- AppCode, an alternative IDE with much more automated refactoring than Xcode
- Clean Coders video series by “Uncle Bob” Martin
Question: What still remains puzzling or challenging about applying TDD to iOS development? Leave a comment below.