Weekly Roundup: Pragmatic Testing

Aaron Brethorst, August 18, 2014

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


Control of the Week

OLEContainerScrollView

OLEContainerScrollView

A UIScrollView subclass that intelligently handles multiple child scroll views and does not interfere with UIKitʼs cell reuse functionality.

MIT licensed.

Find out more Add to Favorites


Weekly Roundup

Timeline

Timeline

Timeline like the Path iOS app

MIT licensed.

Find out more Add to Favorites


SpinKit-ObjC

SpinKit-ObjC

iOS loading component with smooth awesome animation.

MIT licensed.

Find out more Add to Favorites


YLLongTapShare

YLLongTapShare

Long Tap Sharing control for iOS.

MIT licensed.

Find out more Add to Favorites


JGActionSheet

JGActionSheet

A feature-rich action sheet for iOS. It completely replaces UIActionSheet and features many additions:
• Multiple sections.
• Completely customize buttons and labels.
• Sections with custom views.
• Full iPhone & iPad and multi-orientation support.
• Block callbacks.
• Unlimited content capacity thanks to a scroll view.

CocoaPods:
pod 'JGActionSheet'

MIT licensed.

Find out more Add to Favorites


SwiftAppMenuController

SwiftAppMenuController

Facebook's Paper.app like menu adapted to Swift from GTAppMenuController from Gianluca Tursi

MIT licensed.

Find out more Add to Favorites


ODMultiColumnLabel

ODMultiColumnLabel

A UILabel replacement that renders text on multiple columns, comes in both Objective-C and Swift versions

MIT licensed.

Find out more Add to Favorites


AFDateHelper

AFDateHelper

Convenience extension for NSDate in Swift.

MIT licensed.

Find out more Add to Favorites


AFImageHelper

AFImageHelper

Convenience extension for UIImage and UIImageView in Swift

MIT licensed.

Find out more Add to Favorites


AFViewHelper

AFViewHelper

Convenience extension for UIVIew in Swift

MIT licensed.

Find out more Add to Favorites