An addendum to iOS Unit Testing – Getting Started with XCTest

I’ll be the first to admit that I’m a newb with regards to testing. In almost every project, the thought of unit tests had been a luxury (hard to find time when people are demanding features, yesterday, cause everything is literally on fire). So with Swift 2.0 and Xcode 7.0, and especially as of late, I’m very interested in getting up and running with unit testing. Unfortunately, while Apple does a pretty good job of making it painless while working in Xcode, there were a few hiccups I encountered. The errors are still someone obscure, and sometimes don’t point to the exact problem, but point to an approximate one:

Other Notes

  • When working with an upgraded project that uses CocoaPods, pay special attention to the Deployment Target, which may have changed in-between versions. You may have targeted 8.4 and now you need to target 9.0. Be sure to modify this not in the Product Project settings file, but in the Workspace file instead.
  • When working with a whole laundry list of Pods, and who isn’t these days, be sure to pay special attention to the ‘link_with’ syntax of Podfiles. The brain-dead simple way to make sure all your dependencies are in place is simply to do something like (and frankly, who isn’t a fan of brain-dead-simple):link_with ‘Earbits Radio’, ‘Earbits RadioTests’
  • The above will effectively import all your pods into your units tests too. Run ‘pod install’ and you’re done! (This should also take care of any issues you run into with importing a Bridging-Header, you’ll know when you see it).
  • User @testable import rather than import. It’ll save you the trouble of going through and changing the bundle settings of each file. Oh yeah, also go into the project file and enable Testability when in debug mode
  • CircleCI recommends that you bring your pods into your Github Repo, for good reason, you don’t need to constantly be downloading them. I however, hate dealing with merge conflicts with Pods, and so I’d much rather just have them downloaded each time. I’d rather have CircleCI crash earlier than later anyways – it’ll tell me about broken pods before I go an hose my dev environment.