A new issue of Objc.io is out, and this month focuses entirely on testing. I wouldn't say that I'm dogmatic when it comes to my testing practices. Test Driven Development, and its idea of always writing a test before writing new code has never worked right for me 100% of the time. I think it's a great tool to rely upon under the right circumstances, but you need to understand what those circumstances are. One example of where I think it works well is when you understand the inputs and outputs of the function or method you have to write. Unfortunately, this tends to be the exception rather than the rule in my world, and so I typically use unit tests for a completely different purpose: verifying that I don't regress a bug fix in the future.
Usually, the way this works for me is that I'll receive a bug report, verify the issue exists, write a test that exposes the defect, and then make that test go green. When the test passes, the bug is fixed, and should never regress because I'll have a shiny, happy test ensuring that I don't do something profoundly stupid in the future.
Of course, this approach doesn't work very well when the defect happens to be in your UI. And, if your iOS apps look anything like mine, I'm guessing there's a ton of functionality in your view controllers. In this case, I highly recommend seeing if you can refactor the offending code into a different layer of your codebase, or even just a helper object, so that it's easier to write unit tests around it. Failing that, you may have to resort to UI testing. If this is the case, do yourself a huge favor and buy Jonathan Penn's book on Apple's UI Automation framework.
Keep on testing,
Aaron
What We're Reading
- X to Close: The origins of the use of [x] in UI design
- iPhone 6 Reportedly Entering Final Quality Control Stage Ahead of Mass Production
- Swift Function Currying
- Objc.io #15: Testing
- Server-side Config Files
- Debugging file corruption on iOS
- The Race to the Bottom Benefits Platforms (not Developers)
Control of the Week
OLEContainerScrollView
A UIScrollView subclass that intelligently handles multiple child scroll views and does not interfere with UIKitʼs cell reuse functionality. MIT licensed. |
Weekly Roundup
Timeline
Timeline like the Path iOS app MIT licensed. |
SpinKit-ObjC
iOS loading component with smooth awesome animation. MIT licensed. |
YLLongTapShare
Long Tap Sharing control for iOS. MIT licensed. |
JGActionSheet
SwiftAppMenuController
Facebook's Paper.app like menu adapted to Swift from GTAppMenuController from Gianluca Tursi MIT licensed. |
ODMultiColumnLabel
A UILabel replacement that renders text on multiple columns, comes in both Objective-C and Swift versions MIT licensed. |
AFDateHelper
Convenience extension for NSDate in Swift. MIT licensed. |
AFImageHelper
Convenience extension for UIImage and UIImageView in Swift MIT licensed. |
AFViewHelper
Convenience extension for UIVIew in Swift MIT licensed. |