My first 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
Any questions? I’d love to hear your experience with this screencast.
- 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
- Subscribe to this blog and I’ll send you my test code snippets
- AppCode, an alternative IDE with much more automated refactoring than Xcode
- Clean Coders video series by “Uncle Bob” Martin
See also: UIViewController TDD [Screencast]