Automated unit and integration tests (coupled with continuous integration) are a fundamental part of the Socialize SDK. While “test-driven development” is a common buzzword these days, we do more than pay lip service to it. With the iOS variant of the SDK, that involves using a mock object testing framework.

What’s a Mock Object?

As described herehere and here, mock objects are similar to stubs or fakes in that they allow interaction with an external system or framework to be simulated without that system or framework needing to be implemented. For instance, a piece of code that calls a database driver where the “driver” is an object that returns fixed results. A “fake” object implementing stub methods would provide straightforward, deterministic results, but wouldn’t provide the deeper level of behavioral testing and assertion that’s needed to truly put code through its paces. Mock objects provide this, and a number of mock frameworks exist to simplify unit and integration testing for various platforms.

GHUnit and OCMock for iOS

For iOS, the OCMock (OC for “Objective-C,” the language used by iOS) framework is used by the Socialize SDK. OCMock supports stubs and full-blown mock objects, and, together with GHUnit, uses some of the dynamic features of Objective-C for object creation and test running. Although Xcode includes OCUnit, a built-in unit test framework, the richness of features in GHUnit (the combination of it with OCMock is described here) make it an even better choice for unit test creation and running.

GHUnit also includes a UI tool to enable running tests from a device (or an iOS simulator) as well as from the command line:

Essentially, for every feature in the iOS SDK, there’s a corresponding suite of unit tests (and integration tests as well) that are run after every checkin. When a feature is added or changed, it’s the developer’s responsibility to keep the unit tests up to date. These are kept in a separate group in the Xcode project, and the test runner introspects each unit test class and runs the code within them:

One Response to “iOS SDK Testing with GHUnit and OCMock”

  1. [...] priority; currently we are testing our SDK and rectifying some issues with our testing frameworks (GHUnit and OCMock) as they too migrate to iOS 7. In the meantime, we are issuing a pre-release of Socialize SDK [...]

Leave a Reply to The Socialize Blog » IMPORTANT: Upgrading Socialize SDK for iOS 7