Home > GHUnit, iPhone, Open Source, Testing > GHUnit: OCMock Integration

GHUnit: OCMock Integration

As I lined out in a recent post, there is currently no satisfying Testing framework solution available for iPhone projects. I decided to go with GHUnit as it is the most flexible framework and combines the advantages of GTM and SenTestingKit.

Every good Testing framework needs to be integratable with an Isolation Framework. OCMock seems to be the only framework available for Objective-C. Colin Barrett has a nice introduction on how to use OCMock with GTM. His approach is based on the fact that Apple does neither allow linking dynamic libraries, while binaries compiled for the Simulator can without a problem.

GHUnit on the other hand, is compiled as a static library and can therefore be used in both environments, iPhone and Simulator. I think this is one of its major strengths and using plain OCMock would limit me on running Unit tests in the Simulator (what I’m doing most of the time), but from time to time I like to run them on the device just to make sure everything works. Another reason is Integration Testing. In general, there is no need for an Isolation Framework during Integration Testing, but I don’t feel very confident about this at the moment. However, the most important disadvantage would be a further complication of my build process, which I’d like to be clean and easy (GHUnit setup is complicated enough IMHO).

That’s why I decided to integrate OCMock into the GHUnit binaries. I am considering the following usage pattern to be the one with least friction:

  • setup your project to link against static GHUnit library
  • include “GHUnit.h” for unit testing
  • include “OCMock.h” for mocking
  • include “GHUIKitMocks for specialized mocks

The last one is currently in a brainstorm phase. Gabriel Handford has made some efforts to provide Mocks (or are they better called Fakes?) for the CLLocationManager and some network related classes. I have written a UIAccelerometer Fake myself for iRow and that’s why I think there is a general need for specialized UIKit Mocks.

You can find my changes committed here on github.

Categories: GHUnit, iPhone, Open Source, Testing
  1. No comments yet.
  1. October 12, 2009 at 13:49

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: